id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,600 | NetEase/pomelo | lib/connectors/hybrid/tcpsocket.js | function(socket, opts) {
if(!(this instanceof Socket)) {
return new Socket(socket, opts);
}
if(!socket || !opts) {
throw new Error('invalid socket or opts');
}
if(!opts.headSize || typeof opts.headHandler !== 'function') {
throw new Error('invalid opts.headSize or opts.headHandler');
}
// stream style interfaces.
// TODO: need to port to stream2 after node 0.9
Stream.call(this);
this.readable = true;
this.writeable = true;
this._socket = socket;
this.headSize = opts.headSize;
this.closeMethod = opts.closeMethod;
this.headBuffer = new Buffer(opts.headSize);
this.headHandler = opts.headHandler;
this.headOffset = 0;
this.packageOffset = 0;
this.packageSize = 0;
this.packageBuffer = null;
// bind event form the origin socket
this._socket.on('data', ondata.bind(null, this));
this._socket.on('end', onend.bind(null, this));
this._socket.on('error', this.emit.bind(this, 'error'));
this._socket.on('close', this.emit.bind(this, 'close'));
this.state = ST_HEAD;
} | javascript | function(socket, opts) {
if(!(this instanceof Socket)) {
return new Socket(socket, opts);
}
if(!socket || !opts) {
throw new Error('invalid socket or opts');
}
if(!opts.headSize || typeof opts.headHandler !== 'function') {
throw new Error('invalid opts.headSize or opts.headHandler');
}
// stream style interfaces.
// TODO: need to port to stream2 after node 0.9
Stream.call(this);
this.readable = true;
this.writeable = true;
this._socket = socket;
this.headSize = opts.headSize;
this.closeMethod = opts.closeMethod;
this.headBuffer = new Buffer(opts.headSize);
this.headHandler = opts.headHandler;
this.headOffset = 0;
this.packageOffset = 0;
this.packageSize = 0;
this.packageBuffer = null;
// bind event form the origin socket
this._socket.on('data', ondata.bind(null, this));
this._socket.on('end', onend.bind(null, this));
this._socket.on('error', this.emit.bind(this, 'error'));
this._socket.on('close', this.emit.bind(this, 'close'));
this.state = ST_HEAD;
} | [
"function",
"(",
"socket",
",",
"opts",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Socket",
")",
")",
"{",
"return",
"new",
"Socket",
"(",
"socket",
",",
"opts",
")",
";",
"}",
"if",
"(",
"!",
"socket",
"||",
"!",
"opts",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid socket or opts'",
")",
";",
"}",
"if",
"(",
"!",
"opts",
".",
"headSize",
"||",
"typeof",
"opts",
".",
"headHandler",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid opts.headSize or opts.headHandler'",
")",
";",
"}",
"// stream style interfaces.",
"// TODO: need to port to stream2 after node 0.9",
"Stream",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"readable",
"=",
"true",
";",
"this",
".",
"writeable",
"=",
"true",
";",
"this",
".",
"_socket",
"=",
"socket",
";",
"this",
".",
"headSize",
"=",
"opts",
".",
"headSize",
";",
"this",
".",
"closeMethod",
"=",
"opts",
".",
"closeMethod",
";",
"this",
".",
"headBuffer",
"=",
"new",
"Buffer",
"(",
"opts",
".",
"headSize",
")",
";",
"this",
".",
"headHandler",
"=",
"opts",
".",
"headHandler",
";",
"this",
".",
"headOffset",
"=",
"0",
";",
"this",
".",
"packageOffset",
"=",
"0",
";",
"this",
".",
"packageSize",
"=",
"0",
";",
"this",
".",
"packageBuffer",
"=",
"null",
";",
"// bind event form the origin socket",
"this",
".",
"_socket",
".",
"on",
"(",
"'data'",
",",
"ondata",
".",
"bind",
"(",
"null",
",",
"this",
")",
")",
";",
"this",
".",
"_socket",
".",
"on",
"(",
"'end'",
",",
"onend",
".",
"bind",
"(",
"null",
",",
"this",
")",
")",
";",
"this",
".",
"_socket",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"emit",
".",
"bind",
"(",
"this",
",",
"'error'",
")",
")",
";",
"this",
".",
"_socket",
".",
"on",
"(",
"'close'",
",",
"this",
".",
"emit",
".",
"bind",
"(",
"this",
",",
"'close'",
")",
")",
";",
"this",
".",
"state",
"=",
"ST_HEAD",
";",
"}"
] | closed
Tcp socket wrapper with package compositing.
Collect the package from socket and emit a completed package with 'data' event.
Uniform with ws.WebSocket interfaces.
@param {Object} socket origin socket from node.js net module
@param {Object} opts options parameter.
opts.headSize size of package head
opts.headHandler(headBuffer) handler for package head. caculate and return body size from head data. | [
"closed",
"Tcp",
"socket",
"wrapper",
"with",
"package",
"compositing",
".",
"Collect",
"the",
"package",
"from",
"socket",
"and",
"emit",
"a",
"completed",
"package",
"with",
"data",
"event",
".",
"Uniform",
"with",
"ws",
".",
"WebSocket",
"interfaces",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/hybrid/tcpsocket.js#L24-L61 |
|
3,601 | NetEase/pomelo | lib/connectors/hybrid/tcpsocket.js | function(socket, data, offset) {
var hlen = socket.headSize - socket.headOffset;
var dlen = data.length - offset;
var len = Math.min(hlen, dlen);
var dend = offset + len;
data.copy(socket.headBuffer, socket.headOffset, offset, dend);
socket.headOffset += len;
if(socket.headOffset === socket.headSize) {
// if head segment finished
var size = socket.headHandler(socket.headBuffer);
if(size < 0) {
throw new Error('invalid body size: ' + size);
}
// check if header contains a valid type
if(checkTypeData(socket.headBuffer[0])) {
socket.packageSize = size + socket.headSize;
socket.packageBuffer = new Buffer(socket.packageSize);
socket.headBuffer.copy(socket.packageBuffer, 0, 0, socket.headSize);
socket.packageOffset = socket.headSize;
socket.state = ST_BODY;
} else {
dend = data.length;
logger.error('close the connection with invalid head message, the remote ip is %s && port is %s && message is %j', socket._socket.remoteAddress, socket._socket.remotePort, data);
socket.close();
}
}
return dend;
} | javascript | function(socket, data, offset) {
var hlen = socket.headSize - socket.headOffset;
var dlen = data.length - offset;
var len = Math.min(hlen, dlen);
var dend = offset + len;
data.copy(socket.headBuffer, socket.headOffset, offset, dend);
socket.headOffset += len;
if(socket.headOffset === socket.headSize) {
// if head segment finished
var size = socket.headHandler(socket.headBuffer);
if(size < 0) {
throw new Error('invalid body size: ' + size);
}
// check if header contains a valid type
if(checkTypeData(socket.headBuffer[0])) {
socket.packageSize = size + socket.headSize;
socket.packageBuffer = new Buffer(socket.packageSize);
socket.headBuffer.copy(socket.packageBuffer, 0, 0, socket.headSize);
socket.packageOffset = socket.headSize;
socket.state = ST_BODY;
} else {
dend = data.length;
logger.error('close the connection with invalid head message, the remote ip is %s && port is %s && message is %j', socket._socket.remoteAddress, socket._socket.remotePort, data);
socket.close();
}
}
return dend;
} | [
"function",
"(",
"socket",
",",
"data",
",",
"offset",
")",
"{",
"var",
"hlen",
"=",
"socket",
".",
"headSize",
"-",
"socket",
".",
"headOffset",
";",
"var",
"dlen",
"=",
"data",
".",
"length",
"-",
"offset",
";",
"var",
"len",
"=",
"Math",
".",
"min",
"(",
"hlen",
",",
"dlen",
")",
";",
"var",
"dend",
"=",
"offset",
"+",
"len",
";",
"data",
".",
"copy",
"(",
"socket",
".",
"headBuffer",
",",
"socket",
".",
"headOffset",
",",
"offset",
",",
"dend",
")",
";",
"socket",
".",
"headOffset",
"+=",
"len",
";",
"if",
"(",
"socket",
".",
"headOffset",
"===",
"socket",
".",
"headSize",
")",
"{",
"// if head segment finished",
"var",
"size",
"=",
"socket",
".",
"headHandler",
"(",
"socket",
".",
"headBuffer",
")",
";",
"if",
"(",
"size",
"<",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid body size: '",
"+",
"size",
")",
";",
"}",
"// check if header contains a valid type",
"if",
"(",
"checkTypeData",
"(",
"socket",
".",
"headBuffer",
"[",
"0",
"]",
")",
")",
"{",
"socket",
".",
"packageSize",
"=",
"size",
"+",
"socket",
".",
"headSize",
";",
"socket",
".",
"packageBuffer",
"=",
"new",
"Buffer",
"(",
"socket",
".",
"packageSize",
")",
";",
"socket",
".",
"headBuffer",
".",
"copy",
"(",
"socket",
".",
"packageBuffer",
",",
"0",
",",
"0",
",",
"socket",
".",
"headSize",
")",
";",
"socket",
".",
"packageOffset",
"=",
"socket",
".",
"headSize",
";",
"socket",
".",
"state",
"=",
"ST_BODY",
";",
"}",
"else",
"{",
"dend",
"=",
"data",
".",
"length",
";",
"logger",
".",
"error",
"(",
"'close the connection with invalid head message, the remote ip is %s && port is %s && message is %j'",
",",
"socket",
".",
"_socket",
".",
"remoteAddress",
",",
"socket",
".",
"_socket",
".",
"remotePort",
",",
"data",
")",
";",
"socket",
".",
"close",
"(",
")",
";",
"}",
"}",
"return",
"dend",
";",
"}"
] | Read head segment from data to socket.headBuffer.
@param {Object} socket Socket instance
@param {Object} data Buffer instance
@param {Number} offset offset read star from data
@return {Number} new offset of data after read | [
"Read",
"head",
"segment",
"from",
"data",
"to",
"socket",
".",
"headBuffer",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/hybrid/tcpsocket.js#L129-L160 |
|
3,602 | NetEase/pomelo | lib/connectors/hybrid/tcpsocket.js | function(socket, data, offset) {
var blen = socket.packageSize - socket.packageOffset;
var dlen = data.length - offset;
var len = Math.min(blen, dlen);
var dend = offset + len;
data.copy(socket.packageBuffer, socket.packageOffset, offset, dend);
socket.packageOffset += len;
if(socket.packageOffset === socket.packageSize) {
// if all the package finished
var buffer = socket.packageBuffer;
socket.emit('message', buffer);
reset(socket);
}
return dend;
} | javascript | function(socket, data, offset) {
var blen = socket.packageSize - socket.packageOffset;
var dlen = data.length - offset;
var len = Math.min(blen, dlen);
var dend = offset + len;
data.copy(socket.packageBuffer, socket.packageOffset, offset, dend);
socket.packageOffset += len;
if(socket.packageOffset === socket.packageSize) {
// if all the package finished
var buffer = socket.packageBuffer;
socket.emit('message', buffer);
reset(socket);
}
return dend;
} | [
"function",
"(",
"socket",
",",
"data",
",",
"offset",
")",
"{",
"var",
"blen",
"=",
"socket",
".",
"packageSize",
"-",
"socket",
".",
"packageOffset",
";",
"var",
"dlen",
"=",
"data",
".",
"length",
"-",
"offset",
";",
"var",
"len",
"=",
"Math",
".",
"min",
"(",
"blen",
",",
"dlen",
")",
";",
"var",
"dend",
"=",
"offset",
"+",
"len",
";",
"data",
".",
"copy",
"(",
"socket",
".",
"packageBuffer",
",",
"socket",
".",
"packageOffset",
",",
"offset",
",",
"dend",
")",
";",
"socket",
".",
"packageOffset",
"+=",
"len",
";",
"if",
"(",
"socket",
".",
"packageOffset",
"===",
"socket",
".",
"packageSize",
")",
"{",
"// if all the package finished",
"var",
"buffer",
"=",
"socket",
".",
"packageBuffer",
";",
"socket",
".",
"emit",
"(",
"'message'",
",",
"buffer",
")",
";",
"reset",
"(",
"socket",
")",
";",
"}",
"return",
"dend",
";",
"}"
] | Read body segment from data buffer to socket.packageBuffer;
@param {Object} socket Socket instance
@param {Object} data Buffer instance
@param {Number} offset offset read star from data
@return {Number} new offset of data after read | [
"Read",
"body",
"segment",
"from",
"data",
"buffer",
"to",
"socket",
".",
"packageBuffer",
";"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/hybrid/tcpsocket.js#L170-L188 |
|
3,603 | NetEase/pomelo | lib/server/server.js | function(isGlobal, server, msg, session, cb) {
var fm;
if(isGlobal) {
fm = server.globalFilterService;
} else {
fm = server.filterService;
}
if(fm) {
fm.beforeFilter(msg, session, cb);
} else {
utils.invokeCallback(cb);
}
} | javascript | function(isGlobal, server, msg, session, cb) {
var fm;
if(isGlobal) {
fm = server.globalFilterService;
} else {
fm = server.filterService;
}
if(fm) {
fm.beforeFilter(msg, session, cb);
} else {
utils.invokeCallback(cb);
}
} | [
"function",
"(",
"isGlobal",
",",
"server",
",",
"msg",
",",
"session",
",",
"cb",
")",
"{",
"var",
"fm",
";",
"if",
"(",
"isGlobal",
")",
"{",
"fm",
"=",
"server",
".",
"globalFilterService",
";",
"}",
"else",
"{",
"fm",
"=",
"server",
".",
"filterService",
";",
"}",
"if",
"(",
"fm",
")",
"{",
"fm",
".",
"beforeFilter",
"(",
"msg",
",",
"session",
",",
"cb",
")",
";",
"}",
"else",
"{",
"utils",
".",
"invokeCallback",
"(",
"cb",
")",
";",
"}",
"}"
] | Fire before filter chain if any | [
"Fire",
"before",
"filter",
"chain",
"if",
"any"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/server/server.js#L234-L246 |
|
3,604 | NetEase/pomelo | lib/server/server.js | function(isGlobal, server, err, msg, session, resp, opts, cb) {
if(isGlobal) {
cb(err, resp, opts);
// after filter should not interfere response
afterFilter(isGlobal, server, err, msg, session, resp, opts, cb);
} else {
afterFilter(isGlobal, server, err, msg, session, resp, opts, cb);
}
} | javascript | function(isGlobal, server, err, msg, session, resp, opts, cb) {
if(isGlobal) {
cb(err, resp, opts);
// after filter should not interfere response
afterFilter(isGlobal, server, err, msg, session, resp, opts, cb);
} else {
afterFilter(isGlobal, server, err, msg, session, resp, opts, cb);
}
} | [
"function",
"(",
"isGlobal",
",",
"server",
",",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"opts",
",",
"cb",
")",
"{",
"if",
"(",
"isGlobal",
")",
"{",
"cb",
"(",
"err",
",",
"resp",
",",
"opts",
")",
";",
"// after filter should not interfere response",
"afterFilter",
"(",
"isGlobal",
",",
"server",
",",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"opts",
",",
"cb",
")",
";",
"}",
"else",
"{",
"afterFilter",
"(",
"isGlobal",
",",
"server",
",",
"err",
",",
"msg",
",",
"session",
",",
"resp",
",",
"opts",
",",
"cb",
")",
";",
"}",
"}"
] | Send response to client and fire after filter chain if any. | [
"Send",
"response",
"to",
"client",
"and",
"fire",
"after",
"filter",
"chain",
"if",
"any",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/server/server.js#L297-L305 |
|
3,605 | NetEase/pomelo | lib/server/server.js | function(cron, crons, server) {
if(!containCron(cron.id, crons)) {
server.crons.push(cron);
} else {
logger.warn('cron is duplicated: %j', cron);
}
} | javascript | function(cron, crons, server) {
if(!containCron(cron.id, crons)) {
server.crons.push(cron);
} else {
logger.warn('cron is duplicated: %j', cron);
}
} | [
"function",
"(",
"cron",
",",
"crons",
",",
"server",
")",
"{",
"if",
"(",
"!",
"containCron",
"(",
"cron",
".",
"id",
",",
"crons",
")",
")",
"{",
"server",
".",
"crons",
".",
"push",
"(",
"cron",
")",
";",
"}",
"else",
"{",
"logger",
".",
"warn",
"(",
"'cron is duplicated: %j'",
",",
"cron",
")",
";",
"}",
"}"
] | If cron is not in crons then put it in the array. | [
"If",
"cron",
"is",
"not",
"in",
"crons",
"then",
"put",
"it",
"in",
"the",
"array",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/server/server.js#L434-L440 |
|
3,606 | NetEase/pomelo | lib/server/server.js | function(id, crons) {
for(var i=0, l=crons.length; i<l; i++) {
if(id === crons[i].id) {
return true;
}
}
return false;
} | javascript | function(id, crons) {
for(var i=0, l=crons.length; i<l; i++) {
if(id === crons[i].id) {
return true;
}
}
return false;
} | [
"function",
"(",
"id",
",",
"crons",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"crons",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"id",
"===",
"crons",
"[",
"i",
"]",
".",
"id",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if cron is in crons. | [
"Check",
"if",
"cron",
"is",
"in",
"crons",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/server/server.js#L445-L452 |
|
3,607 | NetEase/pomelo | lib/connectors/hybrid/wsprocessor.js | function() {
EventEmitter.call(this);
this.httpServer = new HttpServer();
var self = this;
this.wsServer = new WebSocketServer({server: this.httpServer});
this.wsServer.on('connection', function(socket) {
// emit socket to outside
self.emit('connection', socket);
});
this.state = ST_STARTED;
} | javascript | function() {
EventEmitter.call(this);
this.httpServer = new HttpServer();
var self = this;
this.wsServer = new WebSocketServer({server: this.httpServer});
this.wsServer.on('connection', function(socket) {
// emit socket to outside
self.emit('connection', socket);
});
this.state = ST_STARTED;
} | [
"function",
"(",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"httpServer",
"=",
"new",
"HttpServer",
"(",
")",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"wsServer",
"=",
"new",
"WebSocketServer",
"(",
"{",
"server",
":",
"this",
".",
"httpServer",
"}",
")",
";",
"this",
".",
"wsServer",
".",
"on",
"(",
"'connection'",
",",
"function",
"(",
"socket",
")",
"{",
"// emit socket to outside",
"self",
".",
"emit",
"(",
"'connection'",
",",
"socket",
")",
";",
"}",
")",
";",
"this",
".",
"state",
"=",
"ST_STARTED",
";",
"}"
] | websocket protocol processor | [
"websocket",
"protocol",
"processor"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/hybrid/wsprocessor.js#L12-L25 |
|
3,608 | NetEase/pomelo | lib/util/appUtil.js | function(app, args) {
app.set(Constants.RESERVED.ENV, args.env || process.env.NODE_ENV || Constants.RESERVED.ENV_DEV, true);
} | javascript | function(app, args) {
app.set(Constants.RESERVED.ENV, args.env || process.env.NODE_ENV || Constants.RESERVED.ENV_DEV, true);
} | [
"function",
"(",
"app",
",",
"args",
")",
"{",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"ENV",
",",
"args",
".",
"env",
"||",
"process",
".",
"env",
".",
"NODE_ENV",
"||",
"Constants",
".",
"RESERVED",
".",
"ENV_DEV",
",",
"true",
")",
";",
"}"
] | Setup enviroment. | [
"Setup",
"enviroment",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/util/appUtil.js#L193-L195 |
|
3,609 | NetEase/pomelo | lib/util/appUtil.js | function(app) {
if (process.env.POMELO_LOGGER !== 'off') {
var env = app.get(Constants.RESERVED.ENV);
var originPath = path.join(app.getBase(), Constants.FILEPATH.LOG);
var presentPath = path.join(app.getBase(), Constants.FILEPATH.CONFIG_DIR, env, path.basename(Constants.FILEPATH.LOG));
if(fs.existsSync(originPath)) {
log.configure(app, originPath);
} else if(fs.existsSync(presentPath)) {
log.configure(app, presentPath);
} else {
logger.error('logger file path configuration is error.');
}
}
} | javascript | function(app) {
if (process.env.POMELO_LOGGER !== 'off') {
var env = app.get(Constants.RESERVED.ENV);
var originPath = path.join(app.getBase(), Constants.FILEPATH.LOG);
var presentPath = path.join(app.getBase(), Constants.FILEPATH.CONFIG_DIR, env, path.basename(Constants.FILEPATH.LOG));
if(fs.existsSync(originPath)) {
log.configure(app, originPath);
} else if(fs.existsSync(presentPath)) {
log.configure(app, presentPath);
} else {
logger.error('logger file path configuration is error.');
}
}
} | [
"function",
"(",
"app",
")",
"{",
"if",
"(",
"process",
".",
"env",
".",
"POMELO_LOGGER",
"!==",
"'off'",
")",
"{",
"var",
"env",
"=",
"app",
".",
"get",
"(",
"Constants",
".",
"RESERVED",
".",
"ENV",
")",
";",
"var",
"originPath",
"=",
"path",
".",
"join",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"LOG",
")",
";",
"var",
"presentPath",
"=",
"path",
".",
"join",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"CONFIG_DIR",
",",
"env",
",",
"path",
".",
"basename",
"(",
"Constants",
".",
"FILEPATH",
".",
"LOG",
")",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"originPath",
")",
")",
"{",
"log",
".",
"configure",
"(",
"app",
",",
"originPath",
")",
";",
"}",
"else",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"presentPath",
")",
")",
"{",
"log",
".",
"configure",
"(",
"app",
",",
"presentPath",
")",
";",
"}",
"else",
"{",
"logger",
".",
"error",
"(",
"'logger file path configuration is error.'",
")",
";",
"}",
"}",
"}"
] | Configure custom logger. | [
"Configure",
"custom",
"logger",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/util/appUtil.js#L200-L213 |
|
3,610 | NetEase/pomelo | lib/util/appUtil.js | function(app) {
var filePath = path.join(app.getBase(), Constants.FILEPATH.SERVER_DIR, app.serverType, Constants.FILEPATH.LIFECYCLE);
if(!fs.existsSync(filePath)) {
return;
}
var lifecycle = require(filePath);
for(var key in lifecycle) {
if(typeof lifecycle[key] === 'function') {
app.lifecycleCbs[key] = lifecycle[key];
} else {
logger.warn('lifecycle.js in %s is error format.', filePath);
}
}
} | javascript | function(app) {
var filePath = path.join(app.getBase(), Constants.FILEPATH.SERVER_DIR, app.serverType, Constants.FILEPATH.LIFECYCLE);
if(!fs.existsSync(filePath)) {
return;
}
var lifecycle = require(filePath);
for(var key in lifecycle) {
if(typeof lifecycle[key] === 'function') {
app.lifecycleCbs[key] = lifecycle[key];
} else {
logger.warn('lifecycle.js in %s is error format.', filePath);
}
}
} | [
"function",
"(",
"app",
")",
"{",
"var",
"filePath",
"=",
"path",
".",
"join",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"Constants",
".",
"FILEPATH",
".",
"SERVER_DIR",
",",
"app",
".",
"serverType",
",",
"Constants",
".",
"FILEPATH",
".",
"LIFECYCLE",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"filePath",
")",
")",
"{",
"return",
";",
"}",
"var",
"lifecycle",
"=",
"require",
"(",
"filePath",
")",
";",
"for",
"(",
"var",
"key",
"in",
"lifecycle",
")",
"{",
"if",
"(",
"typeof",
"lifecycle",
"[",
"key",
"]",
"===",
"'function'",
")",
"{",
"app",
".",
"lifecycleCbs",
"[",
"key",
"]",
"=",
"lifecycle",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"logger",
".",
"warn",
"(",
"'lifecycle.js in %s is error format.'",
",",
"filePath",
")",
";",
"}",
"}",
"}"
] | Load lifecycle file. | [
"Load",
"lifecycle",
"file",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/util/appUtil.js#L249-L262 |
|
3,611 | NetEase/pomelo | lib/components/remote.js | function(app) {
var paths = [];
var role;
// master server should not come here
if(app.isFrontend()) {
role = 'frontend';
} else {
role = 'backend';
}
var sysPath = pathUtil.getSysRemotePath(role), serverType = app.getServerType();
if(fs.existsSync(sysPath)) {
paths.push(pathUtil.remotePathRecord('sys', serverType, sysPath));
}
var userPath = pathUtil.getUserRemotePath(app.getBase(), serverType);
if(fs.existsSync(userPath)) {
paths.push(pathUtil.remotePathRecord('user', serverType, userPath));
}
return paths;
} | javascript | function(app) {
var paths = [];
var role;
// master server should not come here
if(app.isFrontend()) {
role = 'frontend';
} else {
role = 'backend';
}
var sysPath = pathUtil.getSysRemotePath(role), serverType = app.getServerType();
if(fs.existsSync(sysPath)) {
paths.push(pathUtil.remotePathRecord('sys', serverType, sysPath));
}
var userPath = pathUtil.getUserRemotePath(app.getBase(), serverType);
if(fs.existsSync(userPath)) {
paths.push(pathUtil.remotePathRecord('user', serverType, userPath));
}
return paths;
} | [
"function",
"(",
"app",
")",
"{",
"var",
"paths",
"=",
"[",
"]",
";",
"var",
"role",
";",
"// master server should not come here",
"if",
"(",
"app",
".",
"isFrontend",
"(",
")",
")",
"{",
"role",
"=",
"'frontend'",
";",
"}",
"else",
"{",
"role",
"=",
"'backend'",
";",
"}",
"var",
"sysPath",
"=",
"pathUtil",
".",
"getSysRemotePath",
"(",
"role",
")",
",",
"serverType",
"=",
"app",
".",
"getServerType",
"(",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"sysPath",
")",
")",
"{",
"paths",
".",
"push",
"(",
"pathUtil",
".",
"remotePathRecord",
"(",
"'sys'",
",",
"serverType",
",",
"sysPath",
")",
")",
";",
"}",
"var",
"userPath",
"=",
"pathUtil",
".",
"getUserRemotePath",
"(",
"app",
".",
"getBase",
"(",
")",
",",
"serverType",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"userPath",
")",
")",
"{",
"paths",
".",
"push",
"(",
"pathUtil",
".",
"remotePathRecord",
"(",
"'user'",
",",
"serverType",
",",
"userPath",
")",
")",
";",
"}",
"return",
"paths",
";",
"}"
] | Get remote paths from application
@param {Object} app current application context
@return {Array} paths | [
"Get",
"remote",
"paths",
"from",
"application"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/remote.js#L77-L98 |
|
3,612 | NetEase/pomelo | lib/components/remote.js | function(app, opts) {
opts.paths = getRemotePaths(app);
opts.context = app;
if(!!opts.rpcServer) {
return opts.rpcServer.create(opts);
} else {
return RemoteServer.create(opts);
}
} | javascript | function(app, opts) {
opts.paths = getRemotePaths(app);
opts.context = app;
if(!!opts.rpcServer) {
return opts.rpcServer.create(opts);
} else {
return RemoteServer.create(opts);
}
} | [
"function",
"(",
"app",
",",
"opts",
")",
"{",
"opts",
".",
"paths",
"=",
"getRemotePaths",
"(",
"app",
")",
";",
"opts",
".",
"context",
"=",
"app",
";",
"if",
"(",
"!",
"!",
"opts",
".",
"rpcServer",
")",
"{",
"return",
"opts",
".",
"rpcServer",
".",
"create",
"(",
"opts",
")",
";",
"}",
"else",
"{",
"return",
"RemoteServer",
".",
"create",
"(",
"opts",
")",
";",
"}",
"}"
] | Generate remote server instance
@param {Object} app current application context
@param {Object} opts contructor parameters for rpc Server
@return {Object} remote server instance | [
"Generate",
"remote",
"server",
"instance"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/remote.js#L107-L115 |
|
3,613 | NetEase/pomelo | lib/components/connector.js | function(app, opts) {
opts = opts || {};
this.app = app;
this.connector = getConnector(app, opts);
this.encode = opts.encode;
this.decode = opts.decode;
this.useCrypto = opts.useCrypto;
this.useHostFilter = opts.useHostFilter;
this.useAsyncCoder = opts.useAsyncCoder;
this.blacklistFun = opts.blacklistFun;
this.keys = {};
this.blacklist = [];
if (opts.useDict) {
app.load(pomelo.dictionary, app.get('dictionaryConfig'));
}
if (opts.useProtobuf) {
app.load(pomelo.protobuf, app.get('protobufConfig'));
}
// component dependencies
this.server = null;
this.session = null;
this.connection = null;
} | javascript | function(app, opts) {
opts = opts || {};
this.app = app;
this.connector = getConnector(app, opts);
this.encode = opts.encode;
this.decode = opts.decode;
this.useCrypto = opts.useCrypto;
this.useHostFilter = opts.useHostFilter;
this.useAsyncCoder = opts.useAsyncCoder;
this.blacklistFun = opts.blacklistFun;
this.keys = {};
this.blacklist = [];
if (opts.useDict) {
app.load(pomelo.dictionary, app.get('dictionaryConfig'));
}
if (opts.useProtobuf) {
app.load(pomelo.protobuf, app.get('protobufConfig'));
}
// component dependencies
this.server = null;
this.session = null;
this.connection = null;
} | [
"function",
"(",
"app",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"app",
"=",
"app",
";",
"this",
".",
"connector",
"=",
"getConnector",
"(",
"app",
",",
"opts",
")",
";",
"this",
".",
"encode",
"=",
"opts",
".",
"encode",
";",
"this",
".",
"decode",
"=",
"opts",
".",
"decode",
";",
"this",
".",
"useCrypto",
"=",
"opts",
".",
"useCrypto",
";",
"this",
".",
"useHostFilter",
"=",
"opts",
".",
"useHostFilter",
";",
"this",
".",
"useAsyncCoder",
"=",
"opts",
".",
"useAsyncCoder",
";",
"this",
".",
"blacklistFun",
"=",
"opts",
".",
"blacklistFun",
";",
"this",
".",
"keys",
"=",
"{",
"}",
";",
"this",
".",
"blacklist",
"=",
"[",
"]",
";",
"if",
"(",
"opts",
".",
"useDict",
")",
"{",
"app",
".",
"load",
"(",
"pomelo",
".",
"dictionary",
",",
"app",
".",
"get",
"(",
"'dictionaryConfig'",
")",
")",
";",
"}",
"if",
"(",
"opts",
".",
"useProtobuf",
")",
"{",
"app",
".",
"load",
"(",
"pomelo",
".",
"protobuf",
",",
"app",
".",
"get",
"(",
"'protobufConfig'",
")",
")",
";",
"}",
"// component dependencies",
"this",
".",
"server",
"=",
"null",
";",
"this",
".",
"session",
"=",
"null",
";",
"this",
".",
"connection",
"=",
"null",
";",
"}"
] | Connector component. Receive client requests and attach session with socket.
@param {Object} app current application context
@param {Object} opts attach parameters
opts.connector {Object} provides low level network and protocol details implementation between server and clients. | [
"Connector",
"component",
".",
"Receive",
"client",
"requests",
"and",
"attach",
"session",
"with",
"socket",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/connector.js#L19-L44 |
|
3,614 | NetEase/pomelo | lib/components/connector.js | function(self, socket) {
var app = self.app,
sid = socket.id;
var session = self.session.get(sid);
if (session) {
return session;
}
session = self.session.create(sid, app.getServerId(), socket);
logger.debug('[%s] getSession session is created with session id: %s', app.getServerId(), sid);
// bind events for session
socket.on('disconnect', session.closed.bind(session));
socket.on('error', session.closed.bind(session));
session.on('closed', onSessionClose.bind(null, app));
session.on('bind', function(uid) {
logger.debug('session on [%s] bind with uid: %s', self.app.serverId, uid);
// update connection statistics if necessary
if (self.connection) {
self.connection.addLoginedUser(uid, {
loginTime: Date.now(),
uid: uid,
address: socket.remoteAddress.ip + ':' + socket.remoteAddress.port
});
}
self.app.event.emit(events.BIND_SESSION, session);
});
session.on('unbind', function(uid) {
if (self.connection) {
self.connection.removeLoginedUser(uid);
}
self.app.event.emit(events.UNBIND_SESSION, session);
});
return session;
} | javascript | function(self, socket) {
var app = self.app,
sid = socket.id;
var session = self.session.get(sid);
if (session) {
return session;
}
session = self.session.create(sid, app.getServerId(), socket);
logger.debug('[%s] getSession session is created with session id: %s', app.getServerId(), sid);
// bind events for session
socket.on('disconnect', session.closed.bind(session));
socket.on('error', session.closed.bind(session));
session.on('closed', onSessionClose.bind(null, app));
session.on('bind', function(uid) {
logger.debug('session on [%s] bind with uid: %s', self.app.serverId, uid);
// update connection statistics if necessary
if (self.connection) {
self.connection.addLoginedUser(uid, {
loginTime: Date.now(),
uid: uid,
address: socket.remoteAddress.ip + ':' + socket.remoteAddress.port
});
}
self.app.event.emit(events.BIND_SESSION, session);
});
session.on('unbind', function(uid) {
if (self.connection) {
self.connection.removeLoginedUser(uid);
}
self.app.event.emit(events.UNBIND_SESSION, session);
});
return session;
} | [
"function",
"(",
"self",
",",
"socket",
")",
"{",
"var",
"app",
"=",
"self",
".",
"app",
",",
"sid",
"=",
"socket",
".",
"id",
";",
"var",
"session",
"=",
"self",
".",
"session",
".",
"get",
"(",
"sid",
")",
";",
"if",
"(",
"session",
")",
"{",
"return",
"session",
";",
"}",
"session",
"=",
"self",
".",
"session",
".",
"create",
"(",
"sid",
",",
"app",
".",
"getServerId",
"(",
")",
",",
"socket",
")",
";",
"logger",
".",
"debug",
"(",
"'[%s] getSession session is created with session id: %s'",
",",
"app",
".",
"getServerId",
"(",
")",
",",
"sid",
")",
";",
"// bind events for session",
"socket",
".",
"on",
"(",
"'disconnect'",
",",
"session",
".",
"closed",
".",
"bind",
"(",
"session",
")",
")",
";",
"socket",
".",
"on",
"(",
"'error'",
",",
"session",
".",
"closed",
".",
"bind",
"(",
"session",
")",
")",
";",
"session",
".",
"on",
"(",
"'closed'",
",",
"onSessionClose",
".",
"bind",
"(",
"null",
",",
"app",
")",
")",
";",
"session",
".",
"on",
"(",
"'bind'",
",",
"function",
"(",
"uid",
")",
"{",
"logger",
".",
"debug",
"(",
"'session on [%s] bind with uid: %s'",
",",
"self",
".",
"app",
".",
"serverId",
",",
"uid",
")",
";",
"// update connection statistics if necessary",
"if",
"(",
"self",
".",
"connection",
")",
"{",
"self",
".",
"connection",
".",
"addLoginedUser",
"(",
"uid",
",",
"{",
"loginTime",
":",
"Date",
".",
"now",
"(",
")",
",",
"uid",
":",
"uid",
",",
"address",
":",
"socket",
".",
"remoteAddress",
".",
"ip",
"+",
"':'",
"+",
"socket",
".",
"remoteAddress",
".",
"port",
"}",
")",
";",
"}",
"self",
".",
"app",
".",
"event",
".",
"emit",
"(",
"events",
".",
"BIND_SESSION",
",",
"session",
")",
";",
"}",
")",
";",
"session",
".",
"on",
"(",
"'unbind'",
",",
"function",
"(",
"uid",
")",
"{",
"if",
"(",
"self",
".",
"connection",
")",
"{",
"self",
".",
"connection",
".",
"removeLoginedUser",
"(",
"uid",
")",
";",
"}",
"self",
".",
"app",
".",
"event",
".",
"emit",
"(",
"events",
".",
"UNBIND_SESSION",
",",
"session",
")",
";",
"}",
")",
";",
"return",
"session",
";",
"}"
] | get session for current connection | [
"get",
"session",
"for",
"current",
"connection"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/connector.js#L331-L367 |
|
3,615 | NetEase/pomelo | lib/components/connector.js | function(route) {
if (!route) {
return null;
}
var idx = route.indexOf('.');
if (idx < 0) {
return null;
}
return route.substring(0, idx);
} | javascript | function(route) {
if (!route) {
return null;
}
var idx = route.indexOf('.');
if (idx < 0) {
return null;
}
return route.substring(0, idx);
} | [
"function",
"(",
"route",
")",
"{",
"if",
"(",
"!",
"route",
")",
"{",
"return",
"null",
";",
"}",
"var",
"idx",
"=",
"route",
".",
"indexOf",
"(",
"'.'",
")",
";",
"if",
"(",
"idx",
"<",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"route",
".",
"substring",
"(",
"0",
",",
"idx",
")",
";",
"}"
] | Get server type form request message. | [
"Get",
"server",
"type",
"form",
"request",
"message",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/connector.js#L406-L415 |
|
3,616 | NetEase/pomelo | lib/components/proxy.js | function(app, opts) {
this.app = app;
this.opts = opts;
this.client = genRpcClient(this.app, opts);
this.app.event.on(events.ADD_SERVERS, this.addServers.bind(this));
this.app.event.on(events.REMOVE_SERVERS, this.removeServers.bind(this));
this.app.event.on(events.REPLACE_SERVERS, this.replaceServers.bind(this));
} | javascript | function(app, opts) {
this.app = app;
this.opts = opts;
this.client = genRpcClient(this.app, opts);
this.app.event.on(events.ADD_SERVERS, this.addServers.bind(this));
this.app.event.on(events.REMOVE_SERVERS, this.removeServers.bind(this));
this.app.event.on(events.REPLACE_SERVERS, this.replaceServers.bind(this));
} | [
"function",
"(",
"app",
",",
"opts",
")",
"{",
"this",
".",
"app",
"=",
"app",
";",
"this",
".",
"opts",
"=",
"opts",
";",
"this",
".",
"client",
"=",
"genRpcClient",
"(",
"this",
".",
"app",
",",
"opts",
")",
";",
"this",
".",
"app",
".",
"event",
".",
"on",
"(",
"events",
".",
"ADD_SERVERS",
",",
"this",
".",
"addServers",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"app",
".",
"event",
".",
"on",
"(",
"events",
".",
"REMOVE_SERVERS",
",",
"this",
".",
"removeServers",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"app",
".",
"event",
".",
"on",
"(",
"events",
".",
"REPLACE_SERVERS",
",",
"this",
".",
"replaceServers",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Proxy component class
@param {Object} app current application context
@param {Object} opts construct parameters | [
"Proxy",
"component",
"class"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/proxy.js#L45-L52 |
|
3,617 | NetEase/pomelo | lib/components/proxy.js | function(app, opts) {
opts.context = app;
opts.routeContext = app;
if(!!opts.rpcClient) {
return opts.rpcClient.create(opts);
} else {
return Client.create(opts);
}
} | javascript | function(app, opts) {
opts.context = app;
opts.routeContext = app;
if(!!opts.rpcClient) {
return opts.rpcClient.create(opts);
} else {
return Client.create(opts);
}
} | [
"function",
"(",
"app",
",",
"opts",
")",
"{",
"opts",
".",
"context",
"=",
"app",
";",
"opts",
".",
"routeContext",
"=",
"app",
";",
"if",
"(",
"!",
"!",
"opts",
".",
"rpcClient",
")",
"{",
"return",
"opts",
".",
"rpcClient",
".",
"create",
"(",
"opts",
")",
";",
"}",
"else",
"{",
"return",
"Client",
".",
"create",
"(",
"opts",
")",
";",
"}",
"}"
] | Generate rpc client
@param {Object} app current application context
@param {Object} opts contructor parameters for rpc client
@return {Object} rpc client | [
"Generate",
"rpc",
"client"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/components/proxy.js#L160-L168 |
|
3,618 | NetEase/pomelo | lib/connectors/siosocket.js | function(id, socket) {
EventEmitter.call(this);
this.id = id;
this.socket = socket;
this.remoteAddress = {
ip: socket.handshake.address.address,
port: socket.handshake.address.port
};
var self = this;
socket.on('disconnect', this.emit.bind(this, 'disconnect'));
socket.on('error', this.emit.bind(this, 'error'));
socket.on('message', function(msg) {
self.emit('message', msg);
});
this.state = ST_INITED;
// TODO: any other events?
} | javascript | function(id, socket) {
EventEmitter.call(this);
this.id = id;
this.socket = socket;
this.remoteAddress = {
ip: socket.handshake.address.address,
port: socket.handshake.address.port
};
var self = this;
socket.on('disconnect', this.emit.bind(this, 'disconnect'));
socket.on('error', this.emit.bind(this, 'error'));
socket.on('message', function(msg) {
self.emit('message', msg);
});
this.state = ST_INITED;
// TODO: any other events?
} | [
"function",
"(",
"id",
",",
"socket",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"id",
"=",
"id",
";",
"this",
".",
"socket",
"=",
"socket",
";",
"this",
".",
"remoteAddress",
"=",
"{",
"ip",
":",
"socket",
".",
"handshake",
".",
"address",
".",
"address",
",",
"port",
":",
"socket",
".",
"handshake",
".",
"address",
".",
"port",
"}",
";",
"var",
"self",
"=",
"this",
";",
"socket",
".",
"on",
"(",
"'disconnect'",
",",
"this",
".",
"emit",
".",
"bind",
"(",
"this",
",",
"'disconnect'",
")",
")",
";",
"socket",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"emit",
".",
"bind",
"(",
"this",
",",
"'error'",
")",
")",
";",
"socket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"msg",
")",
"{",
"self",
".",
"emit",
"(",
"'message'",
",",
"msg",
")",
";",
"}",
")",
";",
"this",
".",
"state",
"=",
"ST_INITED",
";",
"// TODO: any other events?",
"}"
] | Socket class that wraps socket.io socket to provide unified interface for up level. | [
"Socket",
"class",
"that",
"wraps",
"socket",
".",
"io",
"socket",
"to",
"provide",
"unified",
"interface",
"for",
"up",
"level",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/siosocket.js#L10-L32 |
|
3,619 | NetEase/pomelo | lib/connectors/siosocket.js | function(msgs){
var res = '[', msg;
for(var i=0, l=msgs.length; i<l; i++) {
if(i > 0) {
res += ',';
}
msg = msgs[i];
if(typeof msg === 'string') {
res += msg;
} else {
res += JSON.stringify(msg);
}
}
res += ']';
return res;
} | javascript | function(msgs){
var res = '[', msg;
for(var i=0, l=msgs.length; i<l; i++) {
if(i > 0) {
res += ',';
}
msg = msgs[i];
if(typeof msg === 'string') {
res += msg;
} else {
res += JSON.stringify(msg);
}
}
res += ']';
return res;
} | [
"function",
"(",
"msgs",
")",
"{",
"var",
"res",
"=",
"'['",
",",
"msg",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"msgs",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"res",
"+=",
"','",
";",
"}",
"msg",
"=",
"msgs",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"msg",
"===",
"'string'",
")",
"{",
"res",
"+=",
"msg",
";",
"}",
"else",
"{",
"res",
"+=",
"JSON",
".",
"stringify",
"(",
"msg",
")",
";",
"}",
"}",
"res",
"+=",
"']'",
";",
"return",
"res",
";",
"}"
] | Encode batch msg to client | [
"Encode",
"batch",
"msg",
"to",
"client"
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/connectors/siosocket.js#L64-L79 |
|
3,620 | NetEase/pomelo | lib/util/countDownLatch.js | function(count, opts, cb) {
this.count = count;
this.cb = cb;
var self = this;
if (opts.timeout) {
this.timerId = setTimeout(function() {
self.cb(true);
}, opts.timeout);
}
} | javascript | function(count, opts, cb) {
this.count = count;
this.cb = cb;
var self = this;
if (opts.timeout) {
this.timerId = setTimeout(function() {
self.cb(true);
}, opts.timeout);
}
} | [
"function",
"(",
"count",
",",
"opts",
",",
"cb",
")",
"{",
"this",
".",
"count",
"=",
"count",
";",
"this",
".",
"cb",
"=",
"cb",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"opts",
".",
"timeout",
")",
"{",
"this",
".",
"timerId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"cb",
"(",
"true",
")",
";",
"}",
",",
"opts",
".",
"timeout",
")",
";",
"}",
"}"
] | Count down to zero or timeout and invoke cb finally. | [
"Count",
"down",
"to",
"zero",
"or",
"timeout",
"and",
"invoke",
"cb",
"finally",
"."
] | defcf019631ed399cc4dad932d3b028a04a039a4 | https://github.com/NetEase/pomelo/blob/defcf019631ed399cc4dad932d3b028a04a039a4/lib/util/countDownLatch.js#L6-L15 |
|
3,621 | GeekyAnts/vue-native-core | packages/vue-server-renderer/build.js | cached | function cached (fn) {
var cache = Object.create(null);
return (function cachedFn (str) {
var hit = cache[str];
return hit || (cache[str] = fn(str))
})
} | javascript | function cached (fn) {
var cache = Object.create(null);
return (function cachedFn (str) {
var hit = cache[str];
return hit || (cache[str] = fn(str))
})
} | [
"function",
"cached",
"(",
"fn",
")",
"{",
"var",
"cache",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"return",
"(",
"function",
"cachedFn",
"(",
"str",
")",
"{",
"var",
"hit",
"=",
"cache",
"[",
"str",
"]",
";",
"return",
"hit",
"||",
"(",
"cache",
"[",
"str",
"]",
"=",
"fn",
"(",
"str",
")",
")",
"}",
")",
"}"
] | Create a cached version of a pure function. | [
"Create",
"a",
"cached",
"version",
"of",
"a",
"pure",
"function",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L104-L110 |
3,622 | GeekyAnts/vue-native-core | packages/vue-server-renderer/build.js | toObject | function toObject (arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res
} | javascript | function toObject (arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res
} | [
"function",
"toObject",
"(",
"arr",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"arr",
"[",
"i",
"]",
")",
"{",
"extend",
"(",
"res",
",",
"arr",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"res",
"}"
] | Merge an Array of Objects into a single Object. | [
"Merge",
"an",
"Array",
"of",
"Objects",
"into",
"a",
"single",
"Object",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L159-L167 |
3,623 | GeekyAnts/vue-native-core | packages/vue-server-renderer/build.js | genStaticKeys | function genStaticKeys (modules) {
return modules.reduce(function (keys, m) {
return keys.concat(m.staticKeys || [])
}, []).join(',')
} | javascript | function genStaticKeys (modules) {
return modules.reduce(function (keys, m) {
return keys.concat(m.staticKeys || [])
}, []).join(',')
} | [
"function",
"genStaticKeys",
"(",
"modules",
")",
"{",
"return",
"modules",
".",
"reduce",
"(",
"function",
"(",
"keys",
",",
"m",
")",
"{",
"return",
"keys",
".",
"concat",
"(",
"m",
".",
"staticKeys",
"||",
"[",
"]",
")",
"}",
",",
"[",
"]",
")",
".",
"join",
"(",
"','",
")",
"}"
] | Generate a static keys string from compiler modules. | [
"Generate",
"a",
"static",
"keys",
"string",
"from",
"compiler",
"modules",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-server-renderer/build.js#L187-L191 |
3,624 | GeekyAnts/vue-native-core | dist/vue.runtime.common.js | looseEqual | function looseEqual (a, b) {
var isObjectA = isObject(a);
var isObjectB = isObject(b);
if (isObjectA && isObjectB) {
try {
return JSON.stringify(a) === JSON.stringify(b)
} catch (e) {
// possible circular reference
return a === b
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
} | javascript | function looseEqual (a, b) {
var isObjectA = isObject(a);
var isObjectB = isObject(b);
if (isObjectA && isObjectB) {
try {
return JSON.stringify(a) === JSON.stringify(b)
} catch (e) {
// possible circular reference
return a === b
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
} | [
"function",
"looseEqual",
"(",
"a",
",",
"b",
")",
"{",
"var",
"isObjectA",
"=",
"isObject",
"(",
"a",
")",
";",
"var",
"isObjectB",
"=",
"isObject",
"(",
"b",
")",
";",
"if",
"(",
"isObjectA",
"&&",
"isObjectB",
")",
"{",
"try",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"a",
")",
"===",
"JSON",
".",
"stringify",
"(",
"b",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"// possible circular reference",
"return",
"a",
"===",
"b",
"}",
"}",
"else",
"if",
"(",
"!",
"isObjectA",
"&&",
"!",
"isObjectB",
")",
"{",
"return",
"String",
"(",
"a",
")",
"===",
"String",
"(",
"b",
")",
"}",
"else",
"{",
"return",
"false",
"}",
"}"
] | Generate a static keys string from compiler modules.
Check if two values are loosely equal - that is,
if they are plain objects, do they have the same shape? | [
"Generate",
"a",
"static",
"keys",
"string",
"from",
"compiler",
"modules",
".",
"Check",
"if",
"two",
"values",
"are",
"loosely",
"equal",
"-",
"that",
"is",
"if",
"they",
"are",
"plain",
"objects",
"do",
"they",
"have",
"the",
"same",
"shape?"
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L221-L236 |
3,625 | GeekyAnts/vue-native-core | dist/vue.runtime.common.js | once | function once (fn) {
var called = false;
return function () {
if (!called) {
called = true;
fn.apply(this, arguments);
}
}
} | javascript | function once (fn) {
var called = false;
return function () {
if (!called) {
called = true;
fn.apply(this, arguments);
}
}
} | [
"function",
"once",
"(",
"fn",
")",
"{",
"var",
"called",
"=",
"false",
";",
"return",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"called",
")",
"{",
"called",
"=",
"true",
";",
"fn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
"}"
] | Ensure a function is called only once. | [
"Ensure",
"a",
"function",
"is",
"called",
"only",
"once",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L248-L256 |
3,626 | GeekyAnts/vue-native-core | dist/vue.runtime.common.js | simpleNormalizeChildren | function simpleNormalizeChildren (children) {
for (var i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
}
}
return children
} | javascript | function simpleNormalizeChildren (children) {
for (var i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
}
}
return children
} | [
"function",
"simpleNormalizeChildren",
"(",
"children",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"children",
"[",
"i",
"]",
")",
")",
"{",
"return",
"Array",
".",
"prototype",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"children",
")",
"}",
"}",
"return",
"children",
"}"
] | 1. When the children contains components - because a functional component may return an Array instead of a single root. In this case, just a simple normalization is needed - if any child is an Array, we flatten the whole thing with Array.prototype.concat. It is guaranteed to be only 1-level deep because functional components already normalize their own children. | [
"1",
".",
"When",
"the",
"children",
"contains",
"components",
"-",
"because",
"a",
"functional",
"component",
"may",
"return",
"an",
"Array",
"instead",
"of",
"a",
"single",
"root",
".",
"In",
"this",
"case",
"just",
"a",
"simple",
"normalization",
"is",
"needed",
"-",
"if",
"any",
"child",
"is",
"an",
"Array",
"we",
"flatten",
"the",
"whole",
"thing",
"with",
"Array",
".",
"prototype",
".",
"concat",
".",
"It",
"is",
"guaranteed",
"to",
"be",
"only",
"1",
"-",
"level",
"deep",
"because",
"functional",
"components",
"already",
"normalize",
"their",
"own",
"children",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/dist/vue.runtime.common.js#L1771-L1778 |
3,627 | GeekyAnts/vue-native-core | packages/vue-native-helper/build.js | _toString | function _toString(val) {
return val == null
? ''
: typeof val === 'object'
? JSON.stringify(val, null, 2)
: String(val)
} | javascript | function _toString(val) {
return val == null
? ''
: typeof val === 'object'
? JSON.stringify(val, null, 2)
: String(val)
} | [
"function",
"_toString",
"(",
"val",
")",
"{",
"return",
"val",
"==",
"null",
"?",
"''",
":",
"typeof",
"val",
"===",
"'object'",
"?",
"JSON",
".",
"stringify",
"(",
"val",
",",
"null",
",",
"2",
")",
":",
"String",
"(",
"val",
")",
"}"
] | Convert a value to a string that is actually rendered. | [
"Convert",
"a",
"value",
"to",
"a",
"string",
"that",
"is",
"actually",
"rendered",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/vue-native-helper/build.js#L50-L56 |
3,628 | GeekyAnts/vue-native-core | src/platforms/weex/runtime/modules/transition.js | getEnterTargetState | function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
const targetState = {}
const startState = stylesheet[startClass]
const endState = stylesheet[endClass]
const activeState = stylesheet[activeClass]
// 1. fallback to element's default styling
if (startState) {
for (const key in startState) {
targetState[key] = el.style[key]
if (
process.env.NODE_ENV !== 'production' &&
targetState[key] == null &&
(!activeState || activeState[key] == null) &&
(!endState || endState[key] == null)
) {
warn(
`transition property "${key}" is declared in enter starting class (.${startClass}), ` +
`but not declared anywhere in enter ending class (.${endClass}), ` +
`enter active cass (.${activeClass}) or the element's default styling. ` +
`Note in Weex, CSS properties need explicit values to be transitionable.`
)
}
}
}
// 2. if state is mixed in active state, extract them while excluding
// transition properties
if (activeState) {
for (const key in activeState) {
if (key.indexOf('transition') !== 0) {
targetState[key] = activeState[key]
}
}
}
// 3. explicit endState has highest priority
if (endState) {
extend(targetState, endState)
}
return targetState
} | javascript | function getEnterTargetState (el, stylesheet, startClass, endClass, activeClass, vm) {
const targetState = {}
const startState = stylesheet[startClass]
const endState = stylesheet[endClass]
const activeState = stylesheet[activeClass]
// 1. fallback to element's default styling
if (startState) {
for (const key in startState) {
targetState[key] = el.style[key]
if (
process.env.NODE_ENV !== 'production' &&
targetState[key] == null &&
(!activeState || activeState[key] == null) &&
(!endState || endState[key] == null)
) {
warn(
`transition property "${key}" is declared in enter starting class (.${startClass}), ` +
`but not declared anywhere in enter ending class (.${endClass}), ` +
`enter active cass (.${activeClass}) or the element's default styling. ` +
`Note in Weex, CSS properties need explicit values to be transitionable.`
)
}
}
}
// 2. if state is mixed in active state, extract them while excluding
// transition properties
if (activeState) {
for (const key in activeState) {
if (key.indexOf('transition') !== 0) {
targetState[key] = activeState[key]
}
}
}
// 3. explicit endState has highest priority
if (endState) {
extend(targetState, endState)
}
return targetState
} | [
"function",
"getEnterTargetState",
"(",
"el",
",",
"stylesheet",
",",
"startClass",
",",
"endClass",
",",
"activeClass",
",",
"vm",
")",
"{",
"const",
"targetState",
"=",
"{",
"}",
"const",
"startState",
"=",
"stylesheet",
"[",
"startClass",
"]",
"const",
"endState",
"=",
"stylesheet",
"[",
"endClass",
"]",
"const",
"activeState",
"=",
"stylesheet",
"[",
"activeClass",
"]",
"// 1. fallback to element's default styling",
"if",
"(",
"startState",
")",
"{",
"for",
"(",
"const",
"key",
"in",
"startState",
")",
"{",
"targetState",
"[",
"key",
"]",
"=",
"el",
".",
"style",
"[",
"key",
"]",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
"&&",
"targetState",
"[",
"key",
"]",
"==",
"null",
"&&",
"(",
"!",
"activeState",
"||",
"activeState",
"[",
"key",
"]",
"==",
"null",
")",
"&&",
"(",
"!",
"endState",
"||",
"endState",
"[",
"key",
"]",
"==",
"null",
")",
")",
"{",
"warn",
"(",
"`",
"${",
"key",
"}",
"${",
"startClass",
"}",
"`",
"+",
"`",
"${",
"endClass",
"}",
"`",
"+",
"`",
"${",
"activeClass",
"}",
"`",
"+",
"`",
"`",
")",
"}",
"}",
"}",
"// 2. if state is mixed in active state, extract them while excluding",
"// transition properties",
"if",
"(",
"activeState",
")",
"{",
"for",
"(",
"const",
"key",
"in",
"activeState",
")",
"{",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'transition'",
")",
"!==",
"0",
")",
"{",
"targetState",
"[",
"key",
"]",
"=",
"activeState",
"[",
"key",
"]",
"}",
"}",
"}",
"// 3. explicit endState has highest priority",
"if",
"(",
"endState",
")",
"{",
"extend",
"(",
"targetState",
",",
"endState",
")",
"}",
"return",
"targetState",
"}"
] | determine the target animation style for an entering transition. | [
"determine",
"the",
"target",
"animation",
"style",
"for",
"an",
"entering",
"transition",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/src/platforms/weex/runtime/modules/transition.js#L227-L265 |
3,629 | GeekyAnts/vue-native-core | examples/svg/svg.js | function () {
var total = this.stats.length
return this.stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, total)
return point.x + ',' + point.y
}).join(' ')
} | javascript | function () {
var total = this.stats.length
return this.stats.map(function (stat, i) {
var point = valueToPoint(stat.value, i, total)
return point.x + ',' + point.y
}).join(' ')
} | [
"function",
"(",
")",
"{",
"var",
"total",
"=",
"this",
".",
"stats",
".",
"length",
"return",
"this",
".",
"stats",
".",
"map",
"(",
"function",
"(",
"stat",
",",
"i",
")",
"{",
"var",
"point",
"=",
"valueToPoint",
"(",
"stat",
".",
"value",
",",
"i",
",",
"total",
")",
"return",
"point",
".",
"x",
"+",
"','",
"+",
"point",
".",
"y",
"}",
")",
".",
"join",
"(",
"' '",
")",
"}"
] | a computed property for the polygon's points | [
"a",
"computed",
"property",
"for",
"the",
"polygon",
"s",
"points"
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/examples/svg/svg.js#L17-L23 |
|
3,630 | GeekyAnts/vue-native-core | examples/svg/svg.js | valueToPoint | function valueToPoint (value, index, total) {
var x = 0
var y = -value * 0.8
var angle = Math.PI * 2 / total * index
var cos = Math.cos(angle)
var sin = Math.sin(angle)
var tx = x * cos - y * sin + 100
var ty = x * sin + y * cos + 100
return {
x: tx,
y: ty
}
} | javascript | function valueToPoint (value, index, total) {
var x = 0
var y = -value * 0.8
var angle = Math.PI * 2 / total * index
var cos = Math.cos(angle)
var sin = Math.sin(angle)
var tx = x * cos - y * sin + 100
var ty = x * sin + y * cos + 100
return {
x: tx,
y: ty
}
} | [
"function",
"valueToPoint",
"(",
"value",
",",
"index",
",",
"total",
")",
"{",
"var",
"x",
"=",
"0",
"var",
"y",
"=",
"-",
"value",
"*",
"0.8",
"var",
"angle",
"=",
"Math",
".",
"PI",
"*",
"2",
"/",
"total",
"*",
"index",
"var",
"cos",
"=",
"Math",
".",
"cos",
"(",
"angle",
")",
"var",
"sin",
"=",
"Math",
".",
"sin",
"(",
"angle",
")",
"var",
"tx",
"=",
"x",
"*",
"cos",
"-",
"y",
"*",
"sin",
"+",
"100",
"var",
"ty",
"=",
"x",
"*",
"sin",
"+",
"y",
"*",
"cos",
"+",
"100",
"return",
"{",
"x",
":",
"tx",
",",
"y",
":",
"ty",
"}",
"}"
] | math helper... | [
"math",
"helper",
"..."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/examples/svg/svg.js#L48-L60 |
3,631 | GeekyAnts/vue-native-core | packages/weex-vue-framework/factory.js | assertType | function assertType (value, type) {
var valid;
var expectedType = getType(type);
if (expectedType === 'String') {
valid = typeof value === (expectedType = 'string');
} else if (expectedType === 'Number') {
valid = typeof value === (expectedType = 'number');
} else if (expectedType === 'Boolean') {
valid = typeof value === (expectedType = 'boolean');
} else if (expectedType === 'Function') {
valid = typeof value === (expectedType = 'function');
} else if (expectedType === 'Object') {
valid = isPlainObject(value);
} else if (expectedType === 'Array') {
valid = Array.isArray(value);
} else {
valid = value instanceof type;
}
return {
valid: valid,
expectedType: expectedType
}
} | javascript | function assertType (value, type) {
var valid;
var expectedType = getType(type);
if (expectedType === 'String') {
valid = typeof value === (expectedType = 'string');
} else if (expectedType === 'Number') {
valid = typeof value === (expectedType = 'number');
} else if (expectedType === 'Boolean') {
valid = typeof value === (expectedType = 'boolean');
} else if (expectedType === 'Function') {
valid = typeof value === (expectedType = 'function');
} else if (expectedType === 'Object') {
valid = isPlainObject(value);
} else if (expectedType === 'Array') {
valid = Array.isArray(value);
} else {
valid = value instanceof type;
}
return {
valid: valid,
expectedType: expectedType
}
} | [
"function",
"assertType",
"(",
"value",
",",
"type",
")",
"{",
"var",
"valid",
";",
"var",
"expectedType",
"=",
"getType",
"(",
"type",
")",
";",
"if",
"(",
"expectedType",
"===",
"'String'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'string'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Number'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'number'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Boolean'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'boolean'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Function'",
")",
"{",
"valid",
"=",
"typeof",
"value",
"===",
"(",
"expectedType",
"=",
"'function'",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Object'",
")",
"{",
"valid",
"=",
"isPlainObject",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"expectedType",
"===",
"'Array'",
")",
"{",
"valid",
"=",
"Array",
".",
"isArray",
"(",
"value",
")",
";",
"}",
"else",
"{",
"valid",
"=",
"value",
"instanceof",
"type",
";",
"}",
"return",
"{",
"valid",
":",
"valid",
",",
"expectedType",
":",
"expectedType",
"}",
"}"
] | Assert the type of a value | [
"Assert",
"the",
"type",
"of",
"a",
"value"
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/factory.js#L1384-L1406 |
3,632 | GeekyAnts/vue-native-core | packages/weex-vue-framework/index.js | init | function init (cfg) {
renderer.Document = cfg.Document;
renderer.Element = cfg.Element;
renderer.Comment = cfg.Comment;
renderer.sendTasks = cfg.sendTasks;
} | javascript | function init (cfg) {
renderer.Document = cfg.Document;
renderer.Element = cfg.Element;
renderer.Comment = cfg.Comment;
renderer.sendTasks = cfg.sendTasks;
} | [
"function",
"init",
"(",
"cfg",
")",
"{",
"renderer",
".",
"Document",
"=",
"cfg",
".",
"Document",
";",
"renderer",
".",
"Element",
"=",
"cfg",
".",
"Element",
";",
"renderer",
".",
"Comment",
"=",
"cfg",
".",
"Comment",
";",
"renderer",
".",
"sendTasks",
"=",
"cfg",
".",
"sendTasks",
";",
"}"
] | Prepare framework config, basically about the virtual-DOM and JS bridge.
@param {object} cfg | [
"Prepare",
"framework",
"config",
"basically",
"about",
"the",
"virtual",
"-",
"DOM",
"and",
"JS",
"bridge",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/index.js#L33-L38 |
3,633 | GeekyAnts/vue-native-core | packages/weex-vue-framework/index.js | genModuleGetter | function genModuleGetter (instanceId) {
var instance = instances[instanceId];
return function (name) {
var nativeModule = modules[name] || [];
var output = {};
var loop = function ( methodName ) {
output[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var finalArgs = args.map(function (value) {
return normalize(value, instance)
});
renderer.sendTasks(instanceId + '', [{ module: name, method: methodName, args: finalArgs }], -1);
};
};
for (var methodName in nativeModule) loop( methodName );
return output
}
} | javascript | function genModuleGetter (instanceId) {
var instance = instances[instanceId];
return function (name) {
var nativeModule = modules[name] || [];
var output = {};
var loop = function ( methodName ) {
output[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var finalArgs = args.map(function (value) {
return normalize(value, instance)
});
renderer.sendTasks(instanceId + '', [{ module: name, method: methodName, args: finalArgs }], -1);
};
};
for (var methodName in nativeModule) loop( methodName );
return output
}
} | [
"function",
"genModuleGetter",
"(",
"instanceId",
")",
"{",
"var",
"instance",
"=",
"instances",
"[",
"instanceId",
"]",
";",
"return",
"function",
"(",
"name",
")",
"{",
"var",
"nativeModule",
"=",
"modules",
"[",
"name",
"]",
"||",
"[",
"]",
";",
"var",
"output",
"=",
"{",
"}",
";",
"var",
"loop",
"=",
"function",
"(",
"methodName",
")",
"{",
"output",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"while",
"(",
"len",
"--",
")",
"args",
"[",
"len",
"]",
"=",
"arguments",
"[",
"len",
"]",
";",
"var",
"finalArgs",
"=",
"args",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"normalize",
"(",
"value",
",",
"instance",
")",
"}",
")",
";",
"renderer",
".",
"sendTasks",
"(",
"instanceId",
"+",
"''",
",",
"[",
"{",
"module",
":",
"name",
",",
"method",
":",
"methodName",
",",
"args",
":",
"finalArgs",
"}",
"]",
",",
"-",
"1",
")",
";",
"}",
";",
"}",
";",
"for",
"(",
"var",
"methodName",
"in",
"nativeModule",
")",
"loop",
"(",
"methodName",
")",
";",
"return",
"output",
"}",
"}"
] | Generate native module getter. Each native module has several
methods to call. And all the behaviors is instance-related. So
this getter will return a set of methods which additionally
send current instance id to native when called. Also the args
will be normalized into "safe" value. For example function arg
will be converted into a callback id.
@param {string} instanceId
@return {function} | [
"Generate",
"native",
"module",
"getter",
".",
"Each",
"native",
"module",
"has",
"several",
"methods",
"to",
"call",
".",
"And",
"all",
"the",
"behaviors",
"is",
"instance",
"-",
"related",
".",
"So",
"this",
"getter",
"will",
"return",
"a",
"set",
"of",
"methods",
"which",
"additionally",
"send",
"current",
"instance",
"id",
"to",
"native",
"when",
"called",
".",
"Also",
"the",
"args",
"will",
"be",
"normalized",
"into",
"safe",
"value",
".",
"For",
"example",
"function",
"arg",
"will",
"be",
"converted",
"into",
"a",
"callback",
"id",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/packages/weex-vue-framework/index.js#L323-L343 |
3,634 | GeekyAnts/vue-native-core | src/platforms/weex/framework.js | normalize | function normalize (v, instance) {
const type = typof(v)
switch (type) {
case 'undefined':
case 'null':
return ''
case 'regexp':
return v.toString()
case 'date':
return v.toISOString()
case 'number':
case 'string':
case 'boolean':
case 'array':
case 'object':
if (v instanceof renderer.Element) {
return v.ref
}
return v
case 'function':
instance.callbacks[++instance.callbackId] = v
return instance.callbackId.toString()
default:
return JSON.stringify(v)
}
} | javascript | function normalize (v, instance) {
const type = typof(v)
switch (type) {
case 'undefined':
case 'null':
return ''
case 'regexp':
return v.toString()
case 'date':
return v.toISOString()
case 'number':
case 'string':
case 'boolean':
case 'array':
case 'object':
if (v instanceof renderer.Element) {
return v.ref
}
return v
case 'function':
instance.callbacks[++instance.callbackId] = v
return instance.callbackId.toString()
default:
return JSON.stringify(v)
}
} | [
"function",
"normalize",
"(",
"v",
",",
"instance",
")",
"{",
"const",
"type",
"=",
"typof",
"(",
"v",
")",
"switch",
"(",
"type",
")",
"{",
"case",
"'undefined'",
":",
"case",
"'null'",
":",
"return",
"''",
"case",
"'regexp'",
":",
"return",
"v",
".",
"toString",
"(",
")",
"case",
"'date'",
":",
"return",
"v",
".",
"toISOString",
"(",
")",
"case",
"'number'",
":",
"case",
"'string'",
":",
"case",
"'boolean'",
":",
"case",
"'array'",
":",
"case",
"'object'",
":",
"if",
"(",
"v",
"instanceof",
"renderer",
".",
"Element",
")",
"{",
"return",
"v",
".",
"ref",
"}",
"return",
"v",
"case",
"'function'",
":",
"instance",
".",
"callbacks",
"[",
"++",
"instance",
".",
"callbackId",
"]",
"=",
"v",
"return",
"instance",
".",
"callbackId",
".",
"toString",
"(",
")",
"default",
":",
"return",
"JSON",
".",
"stringify",
"(",
"v",
")",
"}",
"}"
] | Convert all type of values into "safe" format to send to native.
1. A `function` will be converted into callback id.
2. An `Element` object will be converted into `ref`.
The `instance` param is used to generate callback id and store
function if necessary.
@param {any} v
@param {object} instance
@return {any} | [
"Convert",
"all",
"type",
"of",
"values",
"into",
"safe",
"format",
"to",
"send",
"to",
"native",
".",
"1",
".",
"A",
"function",
"will",
"be",
"converted",
"into",
"callback",
"id",
".",
"2",
".",
"An",
"Element",
"object",
"will",
"be",
"converted",
"into",
"ref",
".",
"The",
"instance",
"param",
"is",
"used",
"to",
"generate",
"callback",
"id",
"and",
"store",
"function",
"if",
"necessary",
"."
] | a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e | https://github.com/GeekyAnts/vue-native-core/blob/a7b4c9e35fe3f01d7576086f41e5e9ec6975b72e/src/platforms/weex/framework.js#L380-L406 |
3,635 | muaz-khan/RTCMultiConnection | dev/getUserMedia.js | setStreamType | function setStreamType(constraints, stream) {
if (constraints.mandatory && constraints.mandatory.chromeMediaSource) {
stream.isScreen = true;
} else if (constraints.mozMediaSource || constraints.mediaSource) {
stream.isScreen = true;
} else if (constraints.video) {
stream.isVideo = true;
} else if (constraints.audio) {
stream.isAudio = true;
}
} | javascript | function setStreamType(constraints, stream) {
if (constraints.mandatory && constraints.mandatory.chromeMediaSource) {
stream.isScreen = true;
} else if (constraints.mozMediaSource || constraints.mediaSource) {
stream.isScreen = true;
} else if (constraints.video) {
stream.isVideo = true;
} else if (constraints.audio) {
stream.isAudio = true;
}
} | [
"function",
"setStreamType",
"(",
"constraints",
",",
"stream",
")",
"{",
"if",
"(",
"constraints",
".",
"mandatory",
"&&",
"constraints",
".",
"mandatory",
".",
"chromeMediaSource",
")",
"{",
"stream",
".",
"isScreen",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"mozMediaSource",
"||",
"constraints",
".",
"mediaSource",
")",
"{",
"stream",
".",
"isScreen",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"video",
")",
"{",
"stream",
".",
"isVideo",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"constraints",
".",
"audio",
")",
"{",
"stream",
".",
"isAudio",
"=",
"true",
";",
"}",
"}"
] | getUserMediaHandler.js | [
"getUserMediaHandler",
".",
"js"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/getUserMedia.js#L3-L13 |
3,636 | muaz-khan/RTCMultiConnection | dev/XHRConnection.js | xhr | function xhr(url, callback, data) {
if (!window.XMLHttpRequest || !window.JSON) return;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (callback && request.readyState == 4 && request.status == 200) {
// server MUST return JSON text
callback(JSON.parse(request.responseText));
}
};
request.open('POST', url);
var formData = new FormData();
// you're passing "message" parameter
formData.append('message', data);
request.send(formData);
} | javascript | function xhr(url, callback, data) {
if (!window.XMLHttpRequest || !window.JSON) return;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (callback && request.readyState == 4 && request.status == 200) {
// server MUST return JSON text
callback(JSON.parse(request.responseText));
}
};
request.open('POST', url);
var formData = new FormData();
// you're passing "message" parameter
formData.append('message', data);
request.send(formData);
} | [
"function",
"xhr",
"(",
"url",
",",
"callback",
",",
"data",
")",
"{",
"if",
"(",
"!",
"window",
".",
"XMLHttpRequest",
"||",
"!",
"window",
".",
"JSON",
")",
"return",
";",
"var",
"request",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"request",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"callback",
"&&",
"request",
".",
"readyState",
"==",
"4",
"&&",
"request",
".",
"status",
"==",
"200",
")",
"{",
"// server MUST return JSON text",
"callback",
"(",
"JSON",
".",
"parse",
"(",
"request",
".",
"responseText",
")",
")",
";",
"}",
"}",
";",
"request",
".",
"open",
"(",
"'POST'",
",",
"url",
")",
";",
"var",
"formData",
"=",
"new",
"FormData",
"(",
")",
";",
"// you're passing \"message\" parameter",
"formData",
".",
"append",
"(",
"'message'",
",",
"data",
")",
";",
"request",
".",
"send",
"(",
"formData",
")",
";",
"}"
] | a simple function to make XMLHttpRequests | [
"a",
"simple",
"function",
"to",
"make",
"XMLHttpRequests"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/XHRConnection.js#L16-L34 |
3,637 | muaz-khan/RTCMultiConnection | dev/TextSenderReceiver.js | TextReceiver | function TextReceiver(connection) {
var content = {};
function receive(data, userid, extra) {
// uuid is used to uniquely identify sending instance
var uuid = data.uuid;
if (!content[uuid]) {
content[uuid] = [];
}
content[uuid].push(data.message);
if (data.last) {
var message = content[uuid].join('');
if (data.isobject) {
message = JSON.parse(message);
}
// latency detection
var receivingTime = new Date().getTime();
var latency = receivingTime - data.sendingTime;
var e = {
data: message,
userid: userid,
extra: extra,
latency: latency
};
if (connection.autoTranslateText) {
e.original = e.data;
connection.Translator.TranslateText(e.data, function(translatedText) {
e.data = translatedText;
connection.onmessage(e);
});
} else {
connection.onmessage(e);
}
delete content[uuid];
}
}
return {
receive: receive
};
} | javascript | function TextReceiver(connection) {
var content = {};
function receive(data, userid, extra) {
// uuid is used to uniquely identify sending instance
var uuid = data.uuid;
if (!content[uuid]) {
content[uuid] = [];
}
content[uuid].push(data.message);
if (data.last) {
var message = content[uuid].join('');
if (data.isobject) {
message = JSON.parse(message);
}
// latency detection
var receivingTime = new Date().getTime();
var latency = receivingTime - data.sendingTime;
var e = {
data: message,
userid: userid,
extra: extra,
latency: latency
};
if (connection.autoTranslateText) {
e.original = e.data;
connection.Translator.TranslateText(e.data, function(translatedText) {
e.data = translatedText;
connection.onmessage(e);
});
} else {
connection.onmessage(e);
}
delete content[uuid];
}
}
return {
receive: receive
};
} | [
"function",
"TextReceiver",
"(",
"connection",
")",
"{",
"var",
"content",
"=",
"{",
"}",
";",
"function",
"receive",
"(",
"data",
",",
"userid",
",",
"extra",
")",
"{",
"// uuid is used to uniquely identify sending instance",
"var",
"uuid",
"=",
"data",
".",
"uuid",
";",
"if",
"(",
"!",
"content",
"[",
"uuid",
"]",
")",
"{",
"content",
"[",
"uuid",
"]",
"=",
"[",
"]",
";",
"}",
"content",
"[",
"uuid",
"]",
".",
"push",
"(",
"data",
".",
"message",
")",
";",
"if",
"(",
"data",
".",
"last",
")",
"{",
"var",
"message",
"=",
"content",
"[",
"uuid",
"]",
".",
"join",
"(",
"''",
")",
";",
"if",
"(",
"data",
".",
"isobject",
")",
"{",
"message",
"=",
"JSON",
".",
"parse",
"(",
"message",
")",
";",
"}",
"// latency detection",
"var",
"receivingTime",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"var",
"latency",
"=",
"receivingTime",
"-",
"data",
".",
"sendingTime",
";",
"var",
"e",
"=",
"{",
"data",
":",
"message",
",",
"userid",
":",
"userid",
",",
"extra",
":",
"extra",
",",
"latency",
":",
"latency",
"}",
";",
"if",
"(",
"connection",
".",
"autoTranslateText",
")",
"{",
"e",
".",
"original",
"=",
"e",
".",
"data",
";",
"connection",
".",
"Translator",
".",
"TranslateText",
"(",
"e",
".",
"data",
",",
"function",
"(",
"translatedText",
")",
"{",
"e",
".",
"data",
"=",
"translatedText",
";",
"connection",
".",
"onmessage",
"(",
"e",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"connection",
".",
"onmessage",
"(",
"e",
")",
";",
"}",
"delete",
"content",
"[",
"uuid",
"]",
";",
"}",
"}",
"return",
"{",
"receive",
":",
"receive",
"}",
";",
"}"
] | TextReceiver.js & TextSender.js | [
"TextReceiver",
".",
"js",
"&",
"TextSender",
".",
"js"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/TextSenderReceiver.js#L3-L49 |
3,638 | muaz-khan/RTCMultiConnection | dev/MediaStreamRecorder.js | mergeProps | function mergeProps(mergein, mergeto) {
for (var t in mergeto) {
if (typeof mergeto[t] !== 'function') {
mergein[t] = mergeto[t];
}
}
return mergein;
} | javascript | function mergeProps(mergein, mergeto) {
for (var t in mergeto) {
if (typeof mergeto[t] !== 'function') {
mergein[t] = mergeto[t];
}
}
return mergein;
} | [
"function",
"mergeProps",
"(",
"mergein",
",",
"mergeto",
")",
"{",
"for",
"(",
"var",
"t",
"in",
"mergeto",
")",
"{",
"if",
"(",
"typeof",
"mergeto",
"[",
"t",
"]",
"!==",
"'function'",
")",
"{",
"mergein",
"[",
"t",
"]",
"=",
"mergeto",
"[",
"t",
"]",
";",
"}",
"}",
"return",
"mergein",
";",
"}"
] | Merge all other data-types except "function" | [
"Merge",
"all",
"other",
"data",
"-",
"types",
"except",
"function"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L907-L914 |
3,639 | muaz-khan/RTCMultiConnection | dev/MediaStreamRecorder.js | WhammyVideo | function WhammyVideo(duration, quality) {
this.frames = [];
if (!duration) {
duration = 1;
}
this.duration = 1000 / duration;
this.quality = quality || 0.8;
} | javascript | function WhammyVideo(duration, quality) {
this.frames = [];
if (!duration) {
duration = 1;
}
this.duration = 1000 / duration;
this.quality = quality || 0.8;
} | [
"function",
"WhammyVideo",
"(",
"duration",
",",
"quality",
")",
"{",
"this",
".",
"frames",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"duration",
")",
"{",
"duration",
"=",
"1",
";",
"}",
"this",
".",
"duration",
"=",
"1000",
"/",
"duration",
";",
"this",
".",
"quality",
"=",
"quality",
"||",
"0.8",
";",
"}"
] | a more abstract-ish API | [
"a",
"more",
"abstract",
"-",
"ish",
"API"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L2228-L2235 |
3,640 | muaz-khan/RTCMultiConnection | dev/MediaStreamRecorder.js | checkFrames | function checkFrames(frames) {
if (!frames[0]) {
postMessage({
error: 'Something went wrong. Maybe WebP format is not supported in the current browser.'
});
return;
}
var width = frames[0].width,
height = frames[0].height,
duration = frames[0].duration;
for (var i = 1; i < frames.length; i++) {
duration += frames[i].duration;
}
return {
duration: duration,
width: width,
height: height
};
} | javascript | function checkFrames(frames) {
if (!frames[0]) {
postMessage({
error: 'Something went wrong. Maybe WebP format is not supported in the current browser.'
});
return;
}
var width = frames[0].width,
height = frames[0].height,
duration = frames[0].duration;
for (var i = 1; i < frames.length; i++) {
duration += frames[i].duration;
}
return {
duration: duration,
width: width,
height: height
};
} | [
"function",
"checkFrames",
"(",
"frames",
")",
"{",
"if",
"(",
"!",
"frames",
"[",
"0",
"]",
")",
"{",
"postMessage",
"(",
"{",
"error",
":",
"'Something went wrong. Maybe WebP format is not supported in the current browser.'",
"}",
")",
";",
"return",
";",
"}",
"var",
"width",
"=",
"frames",
"[",
"0",
"]",
".",
"width",
",",
"height",
"=",
"frames",
"[",
"0",
"]",
".",
"height",
",",
"duration",
"=",
"frames",
"[",
"0",
"]",
".",
"duration",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"frames",
".",
"length",
";",
"i",
"++",
")",
"{",
"duration",
"+=",
"frames",
"[",
"i",
"]",
".",
"duration",
";",
"}",
"return",
"{",
"duration",
":",
"duration",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
"}",
";",
"}"
] | sums the lengths of all the frames and gets the duration | [
"sums",
"the",
"lengths",
"of",
"all",
"the",
"frames",
"and",
"gets",
"the",
"duration"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/MediaStreamRecorder.js#L2415-L2435 |
3,641 | muaz-khan/RTCMultiConnection | dev/ios-hacks.js | setCordovaAPIs | function setCordovaAPIs() {
// if (DetectRTC.osName !== 'iOS') return;
if (typeof cordova === 'undefined' || typeof cordova.plugins === 'undefined' || typeof cordova.plugins.iosrtc === 'undefined') return;
var iosrtc = cordova.plugins.iosrtc;
window.webkitRTCPeerConnection = iosrtc.RTCPeerConnection;
window.RTCSessionDescription = iosrtc.RTCSessionDescription;
window.RTCIceCandidate = iosrtc.RTCIceCandidate;
window.MediaStream = iosrtc.MediaStream;
window.MediaStreamTrack = iosrtc.MediaStreamTrack;
navigator.getUserMedia = navigator.webkitGetUserMedia = iosrtc.getUserMedia;
iosrtc.debug.enable('iosrtc*');
if (typeof iosrtc.selectAudioOutput == 'function') {
iosrtc.selectAudioOutput(window.iOSDefaultAudioOutputDevice || 'speaker'); // earpiece or speaker
}
iosrtc.registerGlobals();
} | javascript | function setCordovaAPIs() {
// if (DetectRTC.osName !== 'iOS') return;
if (typeof cordova === 'undefined' || typeof cordova.plugins === 'undefined' || typeof cordova.plugins.iosrtc === 'undefined') return;
var iosrtc = cordova.plugins.iosrtc;
window.webkitRTCPeerConnection = iosrtc.RTCPeerConnection;
window.RTCSessionDescription = iosrtc.RTCSessionDescription;
window.RTCIceCandidate = iosrtc.RTCIceCandidate;
window.MediaStream = iosrtc.MediaStream;
window.MediaStreamTrack = iosrtc.MediaStreamTrack;
navigator.getUserMedia = navigator.webkitGetUserMedia = iosrtc.getUserMedia;
iosrtc.debug.enable('iosrtc*');
if (typeof iosrtc.selectAudioOutput == 'function') {
iosrtc.selectAudioOutput(window.iOSDefaultAudioOutputDevice || 'speaker'); // earpiece or speaker
}
iosrtc.registerGlobals();
} | [
"function",
"setCordovaAPIs",
"(",
")",
"{",
"// if (DetectRTC.osName !== 'iOS') return;",
"if",
"(",
"typeof",
"cordova",
"===",
"'undefined'",
"||",
"typeof",
"cordova",
".",
"plugins",
"===",
"'undefined'",
"||",
"typeof",
"cordova",
".",
"plugins",
".",
"iosrtc",
"===",
"'undefined'",
")",
"return",
";",
"var",
"iosrtc",
"=",
"cordova",
".",
"plugins",
".",
"iosrtc",
";",
"window",
".",
"webkitRTCPeerConnection",
"=",
"iosrtc",
".",
"RTCPeerConnection",
";",
"window",
".",
"RTCSessionDescription",
"=",
"iosrtc",
".",
"RTCSessionDescription",
";",
"window",
".",
"RTCIceCandidate",
"=",
"iosrtc",
".",
"RTCIceCandidate",
";",
"window",
".",
"MediaStream",
"=",
"iosrtc",
".",
"MediaStream",
";",
"window",
".",
"MediaStreamTrack",
"=",
"iosrtc",
".",
"MediaStreamTrack",
";",
"navigator",
".",
"getUserMedia",
"=",
"navigator",
".",
"webkitGetUserMedia",
"=",
"iosrtc",
".",
"getUserMedia",
";",
"iosrtc",
".",
"debug",
".",
"enable",
"(",
"'iosrtc*'",
")",
";",
"if",
"(",
"typeof",
"iosrtc",
".",
"selectAudioOutput",
"==",
"'function'",
")",
"{",
"iosrtc",
".",
"selectAudioOutput",
"(",
"window",
".",
"iOSDefaultAudioOutputDevice",
"||",
"'speaker'",
")",
";",
"// earpiece or speaker",
"}",
"iosrtc",
".",
"registerGlobals",
"(",
")",
";",
"}"
] | ios-hacks.js | [
"ios",
"-",
"hacks",
".",
"js"
] | 2032ce949bde30b43a3d2666e0f1e5afbf337f3d | https://github.com/muaz-khan/RTCMultiConnection/blob/2032ce949bde30b43a3d2666e0f1e5afbf337f3d/dev/ios-hacks.js#L3-L20 |
3,642 | getsentry/sentry-javascript | packages/raven-js/plugins/ember.js | emberPlugin | function emberPlugin(Raven, Ember) {
Ember = Ember || window.Ember;
// quit if Ember isn't on the page
if (!Ember) return;
var _oldOnError = Ember.onerror;
Ember.onerror = function EmberOnError(error) {
Raven.captureException(error);
if (typeof _oldOnError === 'function') {
_oldOnError.call(this, error);
}
};
Ember.RSVP.on('error', function(reason) {
if (reason instanceof Error) {
Raven.captureException(reason, {
extra: {context: 'Unhandled Promise error detected'}
});
} else {
Raven.captureMessage('Unhandled Promise error detected', {extra: {reason: reason}});
}
});
} | javascript | function emberPlugin(Raven, Ember) {
Ember = Ember || window.Ember;
// quit if Ember isn't on the page
if (!Ember) return;
var _oldOnError = Ember.onerror;
Ember.onerror = function EmberOnError(error) {
Raven.captureException(error);
if (typeof _oldOnError === 'function') {
_oldOnError.call(this, error);
}
};
Ember.RSVP.on('error', function(reason) {
if (reason instanceof Error) {
Raven.captureException(reason, {
extra: {context: 'Unhandled Promise error detected'}
});
} else {
Raven.captureMessage('Unhandled Promise error detected', {extra: {reason: reason}});
}
});
} | [
"function",
"emberPlugin",
"(",
"Raven",
",",
"Ember",
")",
"{",
"Ember",
"=",
"Ember",
"||",
"window",
".",
"Ember",
";",
"// quit if Ember isn't on the page",
"if",
"(",
"!",
"Ember",
")",
"return",
";",
"var",
"_oldOnError",
"=",
"Ember",
".",
"onerror",
";",
"Ember",
".",
"onerror",
"=",
"function",
"EmberOnError",
"(",
"error",
")",
"{",
"Raven",
".",
"captureException",
"(",
"error",
")",
";",
"if",
"(",
"typeof",
"_oldOnError",
"===",
"'function'",
")",
"{",
"_oldOnError",
".",
"call",
"(",
"this",
",",
"error",
")",
";",
"}",
"}",
";",
"Ember",
".",
"RSVP",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"reason",
")",
"{",
"if",
"(",
"reason",
"instanceof",
"Error",
")",
"{",
"Raven",
".",
"captureException",
"(",
"reason",
",",
"{",
"extra",
":",
"{",
"context",
":",
"'Unhandled Promise error detected'",
"}",
"}",
")",
";",
"}",
"else",
"{",
"Raven",
".",
"captureMessage",
"(",
"'Unhandled Promise error detected'",
",",
"{",
"extra",
":",
"{",
"reason",
":",
"reason",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Ember.js plugin
Patches event handler callbacks and ajax callbacks. | [
"Ember",
".",
"js",
"plugin"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/plugins/ember.js#L6-L28 |
3,643 | getsentry/sentry-javascript | packages/raven-js/Gruntfile.js | AddPluginBrowserifyTransformer | function AddPluginBrowserifyTransformer() {
var noop = function(chunk, _, cb) {
cb(null, chunk);
};
var append = function(cb) {
cb(null, "\nrequire('../src/singleton').addPlugin(module.exports);");
};
return function(file) {
return through(noop, /plugins/.test(file) ? append : undefined);
};
} | javascript | function AddPluginBrowserifyTransformer() {
var noop = function(chunk, _, cb) {
cb(null, chunk);
};
var append = function(cb) {
cb(null, "\nrequire('../src/singleton').addPlugin(module.exports);");
};
return function(file) {
return through(noop, /plugins/.test(file) ? append : undefined);
};
} | [
"function",
"AddPluginBrowserifyTransformer",
"(",
")",
"{",
"var",
"noop",
"=",
"function",
"(",
"chunk",
",",
"_",
",",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"chunk",
")",
";",
"}",
";",
"var",
"append",
"=",
"function",
"(",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"\"\\nrequire('../src/singleton').addPlugin(module.exports);\"",
")",
";",
"}",
";",
"return",
"function",
"(",
"file",
")",
"{",
"return",
"through",
"(",
"noop",
",",
"/",
"plugins",
"/",
".",
"test",
"(",
"file",
")",
"?",
"append",
":",
"undefined",
")",
";",
"}",
";",
"}"
] | custom browserify transformer to re-write plugins to self-register with Raven via addPlugin | [
"custom",
"browserify",
"transformer",
"to",
"re",
"-",
"write",
"plugins",
"to",
"self",
"-",
"register",
"with",
"Raven",
"via",
"addPlugin"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/Gruntfile.js#L26-L36 |
3,644 | getsentry/sentry-javascript | packages/raven-js/src/raven.js | Raven | function Raven() {
this._hasJSON = !!(typeof JSON === 'object' && JSON.stringify);
// Raven can run in contexts where there's no document (react-native)
this._hasDocument = !isUndefined(_document);
this._hasNavigator = !isUndefined(_navigator);
this._lastCapturedException = null;
this._lastData = null;
this._lastEventId = null;
this._globalServer = null;
this._globalKey = null;
this._globalProject = null;
this._globalContext = {};
this._globalOptions = {
// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin
release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
headers: null,
collectWindowErrors: true,
captureUnhandledRejections: true,
maxMessageLength: 0,
// By default, truncates URL values to 250 chars
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1,
sanitizeKeys: []
};
this._fetchDefaults = {
method: 'POST',
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
this._ignoreOnError = 0;
this._isRavenInstalled = false;
this._originalErrorStackTraceLimit = Error.stackTraceLimit;
// capture references to window.console *and* all its methods first
// before the console plugin has a chance to monkey patch
this._originalConsole = _window.console || {};
this._originalConsoleMethods = {};
this._plugins = [];
this._startTime = now();
this._wrappedBuiltIns = [];
this._breadcrumbs = [];
this._lastCapturedEvent = null;
this._keypressTimeout;
this._location = _window.location;
this._lastHref = this._location && this._location.href;
this._resetBackoff();
// eslint-disable-next-line guard-for-in
for (var method in this._originalConsole) {
this._originalConsoleMethods[method] = this._originalConsole[method];
}
} | javascript | function Raven() {
this._hasJSON = !!(typeof JSON === 'object' && JSON.stringify);
// Raven can run in contexts where there's no document (react-native)
this._hasDocument = !isUndefined(_document);
this._hasNavigator = !isUndefined(_navigator);
this._lastCapturedException = null;
this._lastData = null;
this._lastEventId = null;
this._globalServer = null;
this._globalKey = null;
this._globalProject = null;
this._globalContext = {};
this._globalOptions = {
// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin
release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
headers: null,
collectWindowErrors: true,
captureUnhandledRejections: true,
maxMessageLength: 0,
// By default, truncates URL values to 250 chars
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1,
sanitizeKeys: []
};
this._fetchDefaults = {
method: 'POST',
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
this._ignoreOnError = 0;
this._isRavenInstalled = false;
this._originalErrorStackTraceLimit = Error.stackTraceLimit;
// capture references to window.console *and* all its methods first
// before the console plugin has a chance to monkey patch
this._originalConsole = _window.console || {};
this._originalConsoleMethods = {};
this._plugins = [];
this._startTime = now();
this._wrappedBuiltIns = [];
this._breadcrumbs = [];
this._lastCapturedEvent = null;
this._keypressTimeout;
this._location = _window.location;
this._lastHref = this._location && this._location.href;
this._resetBackoff();
// eslint-disable-next-line guard-for-in
for (var method in this._originalConsole) {
this._originalConsoleMethods[method] = this._originalConsole[method];
}
} | [
"function",
"Raven",
"(",
")",
"{",
"this",
".",
"_hasJSON",
"=",
"!",
"!",
"(",
"typeof",
"JSON",
"===",
"'object'",
"&&",
"JSON",
".",
"stringify",
")",
";",
"// Raven can run in contexts where there's no document (react-native)",
"this",
".",
"_hasDocument",
"=",
"!",
"isUndefined",
"(",
"_document",
")",
";",
"this",
".",
"_hasNavigator",
"=",
"!",
"isUndefined",
"(",
"_navigator",
")",
";",
"this",
".",
"_lastCapturedException",
"=",
"null",
";",
"this",
".",
"_lastData",
"=",
"null",
";",
"this",
".",
"_lastEventId",
"=",
"null",
";",
"this",
".",
"_globalServer",
"=",
"null",
";",
"this",
".",
"_globalKey",
"=",
"null",
";",
"this",
".",
"_globalProject",
"=",
"null",
";",
"this",
".",
"_globalContext",
"=",
"{",
"}",
";",
"this",
".",
"_globalOptions",
"=",
"{",
"// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin",
"release",
":",
"_window",
".",
"SENTRY_RELEASE",
"&&",
"_window",
".",
"SENTRY_RELEASE",
".",
"id",
",",
"logger",
":",
"'javascript'",
",",
"ignoreErrors",
":",
"[",
"]",
",",
"ignoreUrls",
":",
"[",
"]",
",",
"whitelistUrls",
":",
"[",
"]",
",",
"includePaths",
":",
"[",
"]",
",",
"headers",
":",
"null",
",",
"collectWindowErrors",
":",
"true",
",",
"captureUnhandledRejections",
":",
"true",
",",
"maxMessageLength",
":",
"0",
",",
"// By default, truncates URL values to 250 chars",
"maxUrlLength",
":",
"250",
",",
"stackTraceLimit",
":",
"50",
",",
"autoBreadcrumbs",
":",
"true",
",",
"instrument",
":",
"true",
",",
"sampleRate",
":",
"1",
",",
"sanitizeKeys",
":",
"[",
"]",
"}",
";",
"this",
".",
"_fetchDefaults",
"=",
"{",
"method",
":",
"'POST'",
",",
"// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default",
"// https://caniuse.com/#feat=referrer-policy",
"// It doesn't. And it throw exception instead of ignoring this parameter...",
"// REF: https://github.com/getsentry/raven-js/issues/1233",
"referrerPolicy",
":",
"supportsReferrerPolicy",
"(",
")",
"?",
"'origin'",
":",
"''",
"}",
";",
"this",
".",
"_ignoreOnError",
"=",
"0",
";",
"this",
".",
"_isRavenInstalled",
"=",
"false",
";",
"this",
".",
"_originalErrorStackTraceLimit",
"=",
"Error",
".",
"stackTraceLimit",
";",
"// capture references to window.console *and* all its methods first",
"// before the console plugin has a chance to monkey patch",
"this",
".",
"_originalConsole",
"=",
"_window",
".",
"console",
"||",
"{",
"}",
";",
"this",
".",
"_originalConsoleMethods",
"=",
"{",
"}",
";",
"this",
".",
"_plugins",
"=",
"[",
"]",
";",
"this",
".",
"_startTime",
"=",
"now",
"(",
")",
";",
"this",
".",
"_wrappedBuiltIns",
"=",
"[",
"]",
";",
"this",
".",
"_breadcrumbs",
"=",
"[",
"]",
";",
"this",
".",
"_lastCapturedEvent",
"=",
"null",
";",
"this",
".",
"_keypressTimeout",
";",
"this",
".",
"_location",
"=",
"_window",
".",
"location",
";",
"this",
".",
"_lastHref",
"=",
"this",
".",
"_location",
"&&",
"this",
".",
"_location",
".",
"href",
";",
"this",
".",
"_resetBackoff",
"(",
")",
";",
"// eslint-disable-next-line guard-for-in",
"for",
"(",
"var",
"method",
"in",
"this",
".",
"_originalConsole",
")",
"{",
"this",
".",
"_originalConsoleMethods",
"[",
"method",
"]",
"=",
"this",
".",
"_originalConsole",
"[",
"method",
"]",
";",
"}",
"}"
] | First, check for JSON support If there is no JSON, we no-op the core features of Raven since JSON is required to encode the payload | [
"First",
"check",
"for",
"JSON",
"support",
"If",
"there",
"is",
"no",
"JSON",
"we",
"no",
"-",
"op",
"the",
"core",
"features",
"of",
"Raven",
"since",
"JSON",
"is",
"required",
"to",
"encode",
"the",
"payload"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L67-L128 |
3,645 | getsentry/sentry-javascript | packages/raven-js/src/raven.js | function() {
TraceKit.report.uninstall();
this._detachPromiseRejectionHandler();
this._unpatchFunctionToString();
this._restoreBuiltIns();
this._restoreConsole();
Error.stackTraceLimit = this._originalErrorStackTraceLimit;
this._isRavenInstalled = false;
return this;
} | javascript | function() {
TraceKit.report.uninstall();
this._detachPromiseRejectionHandler();
this._unpatchFunctionToString();
this._restoreBuiltIns();
this._restoreConsole();
Error.stackTraceLimit = this._originalErrorStackTraceLimit;
this._isRavenInstalled = false;
return this;
} | [
"function",
"(",
")",
"{",
"TraceKit",
".",
"report",
".",
"uninstall",
"(",
")",
";",
"this",
".",
"_detachPromiseRejectionHandler",
"(",
")",
";",
"this",
".",
"_unpatchFunctionToString",
"(",
")",
";",
"this",
".",
"_restoreBuiltIns",
"(",
")",
";",
"this",
".",
"_restoreConsole",
"(",
")",
";",
"Error",
".",
"stackTraceLimit",
"=",
"this",
".",
"_originalErrorStackTraceLimit",
";",
"this",
".",
"_isRavenInstalled",
"=",
"false",
";",
"return",
"this",
";",
"}"
] | Uninstalls the global error handler.
@return {Raven} | [
"Uninstalls",
"the",
"global",
"error",
"handler",
"."
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L406-L418 |
|
3,646 | getsentry/sentry-javascript | packages/raven-js/src/raven.js | function(ex, options) {
options = objectMerge({trimHeadFrames: 0}, options ? options : {});
if (isErrorEvent(ex) && ex.error) {
// If it is an ErrorEvent with `error` property, extract it to get actual Error
ex = ex.error;
} else if (isDOMError(ex) || isDOMException(ex)) {
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
// then we just extract the name and message, as they don't provide anything else
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
var message = ex.message ? name + ': ' + ex.message : name;
return this.captureMessage(
message,
objectMerge(options, {
// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well
// but it's barely any overhead so we may at least try
stacktrace: true,
trimHeadFrames: options.trimHeadFrames + 1
})
);
} else if (isError(ex)) {
// we have a real Error object
ex = ex;
} else if (isPlainObject(ex)) {
// If it is plain Object, serialize it manually and extract options
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
options = this._getCaptureExceptionOptionsFromPlainObject(options, ex);
ex = new Error(options.message);
} else {
// If none of previous checks were valid, then it means that
// it's not a DOMError/DOMException
// it's not a plain Object
// it's not a valid ErrorEvent (one with an error property)
// it's not an Error
// So bail out and capture it as a simple message:
return this.captureMessage(
ex,
objectMerge(options, {
stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace
trimHeadFrames: options.trimHeadFrames + 1
})
);
}
// Store the raw exception object for potential debugging and introspection
this._lastCapturedException = ex;
// TraceKit.report will re-raise any exception passed to it,
// which means you have to wrap it in try/catch. Instead, we
// can wrap it here and only re-raise if TraceKit.report
// raises an exception different from the one we asked to
// report on.
try {
var stack = TraceKit.computeStackTrace(ex);
this._handleStackInfo(stack, options);
} catch (ex1) {
if (ex !== ex1) {
throw ex1;
}
}
return this;
} | javascript | function(ex, options) {
options = objectMerge({trimHeadFrames: 0}, options ? options : {});
if (isErrorEvent(ex) && ex.error) {
// If it is an ErrorEvent with `error` property, extract it to get actual Error
ex = ex.error;
} else if (isDOMError(ex) || isDOMException(ex)) {
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
// then we just extract the name and message, as they don't provide anything else
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
var message = ex.message ? name + ': ' + ex.message : name;
return this.captureMessage(
message,
objectMerge(options, {
// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well
// but it's barely any overhead so we may at least try
stacktrace: true,
trimHeadFrames: options.trimHeadFrames + 1
})
);
} else if (isError(ex)) {
// we have a real Error object
ex = ex;
} else if (isPlainObject(ex)) {
// If it is plain Object, serialize it manually and extract options
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
options = this._getCaptureExceptionOptionsFromPlainObject(options, ex);
ex = new Error(options.message);
} else {
// If none of previous checks were valid, then it means that
// it's not a DOMError/DOMException
// it's not a plain Object
// it's not a valid ErrorEvent (one with an error property)
// it's not an Error
// So bail out and capture it as a simple message:
return this.captureMessage(
ex,
objectMerge(options, {
stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace
trimHeadFrames: options.trimHeadFrames + 1
})
);
}
// Store the raw exception object for potential debugging and introspection
this._lastCapturedException = ex;
// TraceKit.report will re-raise any exception passed to it,
// which means you have to wrap it in try/catch. Instead, we
// can wrap it here and only re-raise if TraceKit.report
// raises an exception different from the one we asked to
// report on.
try {
var stack = TraceKit.computeStackTrace(ex);
this._handleStackInfo(stack, options);
} catch (ex1) {
if (ex !== ex1) {
throw ex1;
}
}
return this;
} | [
"function",
"(",
"ex",
",",
"options",
")",
"{",
"options",
"=",
"objectMerge",
"(",
"{",
"trimHeadFrames",
":",
"0",
"}",
",",
"options",
"?",
"options",
":",
"{",
"}",
")",
";",
"if",
"(",
"isErrorEvent",
"(",
"ex",
")",
"&&",
"ex",
".",
"error",
")",
"{",
"// If it is an ErrorEvent with `error` property, extract it to get actual Error",
"ex",
"=",
"ex",
".",
"error",
";",
"}",
"else",
"if",
"(",
"isDOMError",
"(",
"ex",
")",
"||",
"isDOMException",
"(",
"ex",
")",
")",
"{",
"// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)",
"// then we just extract the name and message, as they don't provide anything else",
"// https://developer.mozilla.org/en-US/docs/Web/API/DOMError",
"// https://developer.mozilla.org/en-US/docs/Web/API/DOMException",
"var",
"name",
"=",
"ex",
".",
"name",
"||",
"(",
"isDOMError",
"(",
"ex",
")",
"?",
"'DOMError'",
":",
"'DOMException'",
")",
";",
"var",
"message",
"=",
"ex",
".",
"message",
"?",
"name",
"+",
"': '",
"+",
"ex",
".",
"message",
":",
"name",
";",
"return",
"this",
".",
"captureMessage",
"(",
"message",
",",
"objectMerge",
"(",
"options",
",",
"{",
"// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well",
"// but it's barely any overhead so we may at least try",
"stacktrace",
":",
"true",
",",
"trimHeadFrames",
":",
"options",
".",
"trimHeadFrames",
"+",
"1",
"}",
")",
")",
";",
"}",
"else",
"if",
"(",
"isError",
"(",
"ex",
")",
")",
"{",
"// we have a real Error object",
"ex",
"=",
"ex",
";",
"}",
"else",
"if",
"(",
"isPlainObject",
"(",
"ex",
")",
")",
"{",
"// If it is plain Object, serialize it manually and extract options",
"// This will allow us to group events based on top-level keys",
"// which is much better than creating new group when any key/value change",
"options",
"=",
"this",
".",
"_getCaptureExceptionOptionsFromPlainObject",
"(",
"options",
",",
"ex",
")",
";",
"ex",
"=",
"new",
"Error",
"(",
"options",
".",
"message",
")",
";",
"}",
"else",
"{",
"// If none of previous checks were valid, then it means that",
"// it's not a DOMError/DOMException",
"// it's not a plain Object",
"// it's not a valid ErrorEvent (one with an error property)",
"// it's not an Error",
"// So bail out and capture it as a simple message:",
"return",
"this",
".",
"captureMessage",
"(",
"ex",
",",
"objectMerge",
"(",
"options",
",",
"{",
"stacktrace",
":",
"true",
",",
"// if we fall back to captureMessage, default to attempting a new trace",
"trimHeadFrames",
":",
"options",
".",
"trimHeadFrames",
"+",
"1",
"}",
")",
")",
";",
"}",
"// Store the raw exception object for potential debugging and introspection",
"this",
".",
"_lastCapturedException",
"=",
"ex",
";",
"// TraceKit.report will re-raise any exception passed to it,",
"// which means you have to wrap it in try/catch. Instead, we",
"// can wrap it here and only re-raise if TraceKit.report",
"// raises an exception different from the one we asked to",
"// report on.",
"try",
"{",
"var",
"stack",
"=",
"TraceKit",
".",
"computeStackTrace",
"(",
"ex",
")",
";",
"this",
".",
"_handleStackInfo",
"(",
"stack",
",",
"options",
")",
";",
"}",
"catch",
"(",
"ex1",
")",
"{",
"if",
"(",
"ex",
"!==",
"ex1",
")",
"{",
"throw",
"ex1",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Manually capture an exception and send it over to Sentry
@param {error} ex An exception to be logged
@param {object} options A specific set of options for this error [optional]
@return {Raven} | [
"Manually",
"capture",
"an",
"exception",
"and",
"send",
"it",
"over",
"to",
"Sentry"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L468-L534 |
|
3,647 | getsentry/sentry-javascript | packages/raven-js/src/raven.js | function(current) {
var last = this._lastData;
if (
!last ||
current.message !== last.message || // defined for captureMessage
current.transaction !== last.transaction // defined for captureException/onerror
)
return false;
// Stacktrace interface (i.e. from captureMessage)
if (current.stacktrace || last.stacktrace) {
return isSameStacktrace(current.stacktrace, last.stacktrace);
} else if (current.exception || last.exception) {
// Exception interface (i.e. from captureException/onerror)
return isSameException(current.exception, last.exception);
} else if (current.fingerprint || last.fingerprint) {
return Boolean(current.fingerprint && last.fingerprint) &&
JSON.stringify(current.fingerprint) === JSON.stringify(last.fingerprint)
}
return true;
} | javascript | function(current) {
var last = this._lastData;
if (
!last ||
current.message !== last.message || // defined for captureMessage
current.transaction !== last.transaction // defined for captureException/onerror
)
return false;
// Stacktrace interface (i.e. from captureMessage)
if (current.stacktrace || last.stacktrace) {
return isSameStacktrace(current.stacktrace, last.stacktrace);
} else if (current.exception || last.exception) {
// Exception interface (i.e. from captureException/onerror)
return isSameException(current.exception, last.exception);
} else if (current.fingerprint || last.fingerprint) {
return Boolean(current.fingerprint && last.fingerprint) &&
JSON.stringify(current.fingerprint) === JSON.stringify(last.fingerprint)
}
return true;
} | [
"function",
"(",
"current",
")",
"{",
"var",
"last",
"=",
"this",
".",
"_lastData",
";",
"if",
"(",
"!",
"last",
"||",
"current",
".",
"message",
"!==",
"last",
".",
"message",
"||",
"// defined for captureMessage",
"current",
".",
"transaction",
"!==",
"last",
".",
"transaction",
"// defined for captureException/onerror",
")",
"return",
"false",
";",
"// Stacktrace interface (i.e. from captureMessage)",
"if",
"(",
"current",
".",
"stacktrace",
"||",
"last",
".",
"stacktrace",
")",
"{",
"return",
"isSameStacktrace",
"(",
"current",
".",
"stacktrace",
",",
"last",
".",
"stacktrace",
")",
";",
"}",
"else",
"if",
"(",
"current",
".",
"exception",
"||",
"last",
".",
"exception",
")",
"{",
"// Exception interface (i.e. from captureException/onerror)",
"return",
"isSameException",
"(",
"current",
".",
"exception",
",",
"last",
".",
"exception",
")",
";",
"}",
"else",
"if",
"(",
"current",
".",
"fingerprint",
"||",
"last",
".",
"fingerprint",
")",
"{",
"return",
"Boolean",
"(",
"current",
".",
"fingerprint",
"&&",
"last",
".",
"fingerprint",
")",
"&&",
"JSON",
".",
"stringify",
"(",
"current",
".",
"fingerprint",
")",
"===",
"JSON",
".",
"stringify",
"(",
"last",
".",
"fingerprint",
")",
"}",
"return",
"true",
";",
"}"
] | Returns true if the in-process data payload matches the signature
of the previously-sent data
NOTE: This has to be done at this level because TraceKit can generate
data from window.onerror WITHOUT an exception object (IE8, IE9,
other old browsers). This can take the form of an "exception"
data object with a single frame (derived from the onerror args). | [
"Returns",
"true",
"if",
"the",
"in",
"-",
"process",
"data",
"payload",
"matches",
"the",
"signature",
"of",
"the",
"previously",
"-",
"sent",
"data"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/src/raven.js#L1908-L1930 |
|
3,648 | getsentry/sentry-javascript | packages/browser/src/loader.js | function(content) {
// content.e = error
// content.p = promise rejection
// content.f = function call the Sentry
if (
(content.e ||
content.p ||
(content.f && content.f.indexOf('capture') > -1) ||
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
lazy
) {
// We only want to lazy inject/load the sdk bundle if
// an error or promise rejection occured
// OR someone called `capture...` on the SDK
injectSdk(onLoadCallbacks);
}
queue.data.push(content);
} | javascript | function(content) {
// content.e = error
// content.p = promise rejection
// content.f = function call the Sentry
if (
(content.e ||
content.p ||
(content.f && content.f.indexOf('capture') > -1) ||
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
lazy
) {
// We only want to lazy inject/load the sdk bundle if
// an error or promise rejection occured
// OR someone called `capture...` on the SDK
injectSdk(onLoadCallbacks);
}
queue.data.push(content);
} | [
"function",
"(",
"content",
")",
"{",
"// content.e = error",
"// content.p = promise rejection",
"// content.f = function call the Sentry",
"if",
"(",
"(",
"content",
".",
"e",
"||",
"content",
".",
"p",
"||",
"(",
"content",
".",
"f",
"&&",
"content",
".",
"f",
".",
"indexOf",
"(",
"'capture'",
")",
">",
"-",
"1",
")",
"||",
"(",
"content",
".",
"f",
"&&",
"content",
".",
"f",
".",
"indexOf",
"(",
"'showReportDialog'",
")",
">",
"-",
"1",
")",
")",
"&&",
"lazy",
")",
"{",
"// We only want to lazy inject/load the sdk bundle if",
"// an error or promise rejection occured",
"// OR someone called `capture...` on the SDK",
"injectSdk",
"(",
"onLoadCallbacks",
")",
";",
"}",
"queue",
".",
"data",
".",
"push",
"(",
"content",
")",
";",
"}"
] | Create a namespace and attach function that will store captured exception Because functions are also objects, we can attach the queue itself straight to it and save some bytes | [
"Create",
"a",
"namespace",
"and",
"attach",
"function",
"that",
"will",
"store",
"captured",
"exception",
"Because",
"functions",
"are",
"also",
"objects",
"we",
"can",
"attach",
"the",
"queue",
"itself",
"straight",
"to",
"it",
"and",
"save",
"some",
"bytes"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/browser/src/loader.js#L29-L46 |
|
3,649 | getsentry/sentry-javascript | packages/raven-js/scripts/generate-plugin-combinations.js | generate | function generate(plugins, dest) {
const pluginNames = plugins.map((plugin) => {
return path.basename(plugin, '.js');
});
const pluginCombinations = combine(pluginNames);
pluginCombinations.forEach((pluginCombination) => {
fs.writeFileSync(
path.resolve(dest, `${pluginCombination.join(',')}.js`),
template(pluginCombination),
);
});
} | javascript | function generate(plugins, dest) {
const pluginNames = plugins.map((plugin) => {
return path.basename(plugin, '.js');
});
const pluginCombinations = combine(pluginNames);
pluginCombinations.forEach((pluginCombination) => {
fs.writeFileSync(
path.resolve(dest, `${pluginCombination.join(',')}.js`),
template(pluginCombination),
);
});
} | [
"function",
"generate",
"(",
"plugins",
",",
"dest",
")",
"{",
"const",
"pluginNames",
"=",
"plugins",
".",
"map",
"(",
"(",
"plugin",
")",
"=>",
"{",
"return",
"path",
".",
"basename",
"(",
"plugin",
",",
"'.js'",
")",
";",
"}",
")",
";",
"const",
"pluginCombinations",
"=",
"combine",
"(",
"pluginNames",
")",
";",
"pluginCombinations",
".",
"forEach",
"(",
"(",
"pluginCombination",
")",
"=>",
"{",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"resolve",
"(",
"dest",
",",
"`",
"${",
"pluginCombination",
".",
"join",
"(",
"','",
")",
"}",
"`",
")",
",",
"template",
"(",
"pluginCombination",
")",
",",
")",
";",
"}",
")",
";",
"}"
] | Generate all plugin combinations.
@param {array} plugins
@param {string} dest | [
"Generate",
"all",
"plugin",
"combinations",
"."
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/scripts/generate-plugin-combinations.js#L46-L59 |
3,650 | getsentry/sentry-javascript | packages/raven-node/lib/client.js | Client | function Client(dsn, options) {
if (dsn instanceof Client) return dsn;
var ravenInstance = new Raven();
return ravenInstance.config.apply(ravenInstance, arguments);
} | javascript | function Client(dsn, options) {
if (dsn instanceof Client) return dsn;
var ravenInstance = new Raven();
return ravenInstance.config.apply(ravenInstance, arguments);
} | [
"function",
"Client",
"(",
"dsn",
",",
"options",
")",
"{",
"if",
"(",
"dsn",
"instanceof",
"Client",
")",
"return",
"dsn",
";",
"var",
"ravenInstance",
"=",
"new",
"Raven",
"(",
")",
";",
"return",
"ravenInstance",
".",
"config",
".",
"apply",
"(",
"ravenInstance",
",",
"arguments",
")",
";",
"}"
] | Maintain old API compat, need to make sure arguments length is preserved | [
"Maintain",
"old",
"API",
"compat",
"need",
"to",
"make",
"sure",
"arguments",
"length",
"is",
"preserved"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-node/lib/client.js#L662-L666 |
3,651 | getsentry/sentry-javascript | packages/raven-js/scripts/build.js | build | async function build(inputOptions, outputOptions) {
const input = Object.assign(
{
plugins: [
commonjs(), // We can remove this plugin if there are no more CommonJS modules
resolve(), // We need this plugin only to build the test script
babel({
exclude: 'node_modules/**'
})
]
},
inputOptions
);
const output = Object.assign(
{
format: 'umd'
},
outputOptions
);
const bundle = await rollup(input);
await bundle.write(output);
} | javascript | async function build(inputOptions, outputOptions) {
const input = Object.assign(
{
plugins: [
commonjs(), // We can remove this plugin if there are no more CommonJS modules
resolve(), // We need this plugin only to build the test script
babel({
exclude: 'node_modules/**'
})
]
},
inputOptions
);
const output = Object.assign(
{
format: 'umd'
},
outputOptions
);
const bundle = await rollup(input);
await bundle.write(output);
} | [
"async",
"function",
"build",
"(",
"inputOptions",
",",
"outputOptions",
")",
"{",
"const",
"input",
"=",
"Object",
".",
"assign",
"(",
"{",
"plugins",
":",
"[",
"commonjs",
"(",
")",
",",
"// We can remove this plugin if there are no more CommonJS modules",
"resolve",
"(",
")",
",",
"// We need this plugin only to build the test script",
"babel",
"(",
"{",
"exclude",
":",
"'node_modules/**'",
"}",
")",
"]",
"}",
",",
"inputOptions",
")",
";",
"const",
"output",
"=",
"Object",
".",
"assign",
"(",
"{",
"format",
":",
"'umd'",
"}",
",",
"outputOptions",
")",
";",
"const",
"bundle",
"=",
"await",
"rollup",
"(",
"input",
")",
";",
"await",
"bundle",
".",
"write",
"(",
"output",
")",
";",
"}"
] | Only needed for test build
Build using rollup.js
@see https://rollupjs.org/#javascript-api
@param inputOptions
@param outputOptions
@returns Promise | [
"Only",
"needed",
"for",
"test",
"build",
"Build",
"using",
"rollup",
".",
"js"
] | a872223343fecf7364473b78bede937f1eb57bd0 | https://github.com/getsentry/sentry-javascript/blob/a872223343fecf7364473b78bede937f1eb57bd0/packages/raven-js/scripts/build.js#L15-L38 |
3,652 | Project-OSRM/osrm-backend | scripts/osrm-runner.js | ServerDetails | function ServerDetails(x) {
if (!(this instanceof ServerDetails)) return new ServerDetails(x);
const v = x.split(':');
this.hostname = (v[0].length > 0) ? v[0] : '';
this.port = (v.length > 1) ? Number(v[1]) : 80;
} | javascript | function ServerDetails(x) {
if (!(this instanceof ServerDetails)) return new ServerDetails(x);
const v = x.split(':');
this.hostname = (v[0].length > 0) ? v[0] : '';
this.port = (v.length > 1) ? Number(v[1]) : 80;
} | [
"function",
"ServerDetails",
"(",
"x",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ServerDetails",
")",
")",
"return",
"new",
"ServerDetails",
"(",
"x",
")",
";",
"const",
"v",
"=",
"x",
".",
"split",
"(",
"':'",
")",
";",
"this",
".",
"hostname",
"=",
"(",
"v",
"[",
"0",
"]",
".",
"length",
">",
"0",
")",
"?",
"v",
"[",
"0",
"]",
":",
"''",
";",
"this",
".",
"port",
"=",
"(",
"v",
".",
"length",
">",
"1",
")",
"?",
"Number",
"(",
"v",
"[",
"1",
"]",
")",
":",
"80",
";",
"}"
] | Command line arguments | [
"Command",
"line",
"arguments"
] | e86d93760f51304940d55d62c0d47f15094d6712 | https://github.com/Project-OSRM/osrm-backend/blob/e86d93760f51304940d55d62c0d47f15094d6712/scripts/osrm-runner.js#L86-L91 |
3,653 | wix/react-native-ui-lib | scripts/utils/propTypesHandler.js | propTypesDocsHandler | function propTypesDocsHandler(documentation, path) {
const propTypesPath = getMemberValuePath(path, 'propTypes');
const docComment = getDocblock(propTypesPath.parent);
const statementPattern = /@.*\:/;
const info = {};
if (docComment) {
const infoRaw = _.split(docComment, '\n');
_.forEach(infoRaw, (statement) => {
if (statement && statementPattern.test(statement)) {
const key = statement.match(statementPattern)[0].slice(1, -1);
info[key] = statement.split(statementPattern)[1].trim();
}
});
}
documentation.set('propsInfo', info);
} | javascript | function propTypesDocsHandler(documentation, path) {
const propTypesPath = getMemberValuePath(path, 'propTypes');
const docComment = getDocblock(propTypesPath.parent);
const statementPattern = /@.*\:/;
const info = {};
if (docComment) {
const infoRaw = _.split(docComment, '\n');
_.forEach(infoRaw, (statement) => {
if (statement && statementPattern.test(statement)) {
const key = statement.match(statementPattern)[0].slice(1, -1);
info[key] = statement.split(statementPattern)[1].trim();
}
});
}
documentation.set('propsInfo', info);
} | [
"function",
"propTypesDocsHandler",
"(",
"documentation",
",",
"path",
")",
"{",
"const",
"propTypesPath",
"=",
"getMemberValuePath",
"(",
"path",
",",
"'propTypes'",
")",
";",
"const",
"docComment",
"=",
"getDocblock",
"(",
"propTypesPath",
".",
"parent",
")",
";",
"const",
"statementPattern",
"=",
"/",
"@.*\\:",
"/",
";",
"const",
"info",
"=",
"{",
"}",
";",
"if",
"(",
"docComment",
")",
"{",
"const",
"infoRaw",
"=",
"_",
".",
"split",
"(",
"docComment",
",",
"'\\n'",
")",
";",
"_",
".",
"forEach",
"(",
"infoRaw",
",",
"(",
"statement",
")",
"=>",
"{",
"if",
"(",
"statement",
"&&",
"statementPattern",
".",
"test",
"(",
"statement",
")",
")",
"{",
"const",
"key",
"=",
"statement",
".",
"match",
"(",
"statementPattern",
")",
"[",
"0",
"]",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"info",
"[",
"key",
"]",
"=",
"statement",
".",
"split",
"(",
"statementPattern",
")",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"documentation",
".",
"set",
"(",
"'propsInfo'",
",",
"info",
")",
";",
"}"
] | Extract info on the component props | [
"Extract",
"info",
"on",
"the",
"component",
"props"
] | 439d36c7932bc3cfe574320e8f214a03f988c5ac | https://github.com/wix/react-native-ui-lib/blob/439d36c7932bc3cfe574320e8f214a03f988c5ac/scripts/utils/propTypesHandler.js#L10-L26 |
3,654 | wuchangming/spy-debugger | buildin_modules/weinre/web/client/inspector.js | flushQueue | function flushQueue()
{
var queued = WebInspector.log.queued;
if (!queued)
return;
for (var i = 0; i < queued.length; ++i)
logMessage(queued[i]);
delete WebInspector.log.queued;
} | javascript | function flushQueue()
{
var queued = WebInspector.log.queued;
if (!queued)
return;
for (var i = 0; i < queued.length; ++i)
logMessage(queued[i]);
delete WebInspector.log.queued;
} | [
"function",
"flushQueue",
"(",
")",
"{",
"var",
"queued",
"=",
"WebInspector",
".",
"log",
".",
"queued",
";",
"if",
"(",
"!",
"queued",
")",
"return",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"queued",
".",
"length",
";",
"++",
"i",
")",
"logMessage",
"(",
"queued",
"[",
"i",
"]",
")",
";",
"delete",
"WebInspector",
".",
"log",
".",
"queued",
";",
"}"
] | flush the queue of pending messages | [
"flush",
"the",
"queue",
"of",
"pending",
"messages"
] | 55c1dda0dff0c44920673711656ddfd7ff03c307 | https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/inspector.js#L1213-L1223 |
3,655 | wuchangming/spy-debugger | buildin_modules/weinre/web/client/inspector.js | flushQueueIfAvailable | function flushQueueIfAvailable()
{
if (!isLogAvailable())
return;
clearInterval(WebInspector.log.interval);
delete WebInspector.log.interval;
flushQueue();
} | javascript | function flushQueueIfAvailable()
{
if (!isLogAvailable())
return;
clearInterval(WebInspector.log.interval);
delete WebInspector.log.interval;
flushQueue();
} | [
"function",
"flushQueueIfAvailable",
"(",
")",
"{",
"if",
"(",
"!",
"isLogAvailable",
"(",
")",
")",
"return",
";",
"clearInterval",
"(",
"WebInspector",
".",
"log",
".",
"interval",
")",
";",
"delete",
"WebInspector",
".",
"log",
".",
"interval",
";",
"flushQueue",
"(",
")",
";",
"}"
] | flush the queue if it console is available - this function is run on an interval | [
"flush",
"the",
"queue",
"if",
"it",
"console",
"is",
"available",
"-",
"this",
"function",
"is",
"run",
"on",
"an",
"interval"
] | 55c1dda0dff0c44920673711656ddfd7ff03c307 | https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/inspector.js#L1227-L1236 |
3,656 | wuchangming/spy-debugger | buildin_modules/weinre/web/client/UglifyJS/process.js | fixrefs | function fixrefs(scope, i) {
// do children first; order shouldn't matter
for (i = scope.children.length; --i >= 0;)
fixrefs(scope.children[i]);
for (i in scope.refs) if (HOP(scope.refs, i)) {
// find origin scope and propagate the reference to origin
for (var origin = scope.has(i), s = scope; s; s = s.parent) {
s.refs[i] = origin;
if (s === origin) break;
}
}
} | javascript | function fixrefs(scope, i) {
// do children first; order shouldn't matter
for (i = scope.children.length; --i >= 0;)
fixrefs(scope.children[i]);
for (i in scope.refs) if (HOP(scope.refs, i)) {
// find origin scope and propagate the reference to origin
for (var origin = scope.has(i), s = scope; s; s = s.parent) {
s.refs[i] = origin;
if (s === origin) break;
}
}
} | [
"function",
"fixrefs",
"(",
"scope",
",",
"i",
")",
"{",
"// do children first; order shouldn't matter",
"for",
"(",
"i",
"=",
"scope",
".",
"children",
".",
"length",
";",
"--",
"i",
">=",
"0",
";",
")",
"fixrefs",
"(",
"scope",
".",
"children",
"[",
"i",
"]",
")",
";",
"for",
"(",
"i",
"in",
"scope",
".",
"refs",
")",
"if",
"(",
"HOP",
"(",
"scope",
".",
"refs",
",",
"i",
")",
")",
"{",
"// find origin scope and propagate the reference to origin",
"for",
"(",
"var",
"origin",
"=",
"scope",
".",
"has",
"(",
"i",
")",
",",
"s",
"=",
"scope",
";",
"s",
";",
"s",
"=",
"s",
".",
"parent",
")",
"{",
"s",
".",
"refs",
"[",
"i",
"]",
"=",
"origin",
";",
"if",
"(",
"s",
"===",
"origin",
")",
"break",
";",
"}",
"}",
"}"
] | for referenced names it might be useful to know their origin scope. current_scope here is the toplevel one. | [
"for",
"referenced",
"names",
"it",
"might",
"be",
"useful",
"to",
"know",
"their",
"origin",
"scope",
".",
"current_scope",
"here",
"is",
"the",
"toplevel",
"one",
"."
] | 55c1dda0dff0c44920673711656ddfd7ff03c307 | https://github.com/wuchangming/spy-debugger/blob/55c1dda0dff0c44920673711656ddfd7ff03c307/buildin_modules/weinre/web/client/UglifyJS/process.js#L439-L450 |
3,657 | ai/size-limit | index.js | getSize | async function getSize (files, opts) {
if (typeof files === 'string') files = [files]
if (!opts) opts = { }
if (opts.webpack === false) {
let sizes = await Promise.all(files.map(async file => {
let bytes = await readFile(file, 'utf8')
let result = { parsed: bytes.length }
if (opts.running !== false) result.running = await getRunningTime(file)
if (opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = await gzipSize(bytes)
result.loading = getLoadingTime(result.gzip)
}
return result
}))
return sizes.reduce(sumSize)
} else {
let config = getConfig(files, opts)
let output = path.join(
config.output.path || process.cwd(), config.output.filename)
let size, running
try {
let stats = await runWebpack(config)
if (opts.running !== false) running = await getRunningTime(output)
if (stats.hasErrors()) {
throw new Error(stats.toString('errors-only'))
}
if (opts.config && stats.stats) {
size = stats.stats
.map(stat => extractSize(stat.toJson(), opts))
.reduce(sumSize)
} else {
size = extractSize(stats.toJson(), opts)
}
} finally {
if (config.output.path && !opts.output) {
await del(config.output.path, { force: true })
}
}
let result = { parsed: size.parsed - WEBPACK_EMPTY_PROJECT_PARSED }
if (opts.running !== false) result.running = running
if (opts.config || opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = size.gzip - WEBPACK_EMPTY_PROJECT_GZIP
result.loading = getLoadingTime(result.gzip)
}
return result
}
} | javascript | async function getSize (files, opts) {
if (typeof files === 'string') files = [files]
if (!opts) opts = { }
if (opts.webpack === false) {
let sizes = await Promise.all(files.map(async file => {
let bytes = await readFile(file, 'utf8')
let result = { parsed: bytes.length }
if (opts.running !== false) result.running = await getRunningTime(file)
if (opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = await gzipSize(bytes)
result.loading = getLoadingTime(result.gzip)
}
return result
}))
return sizes.reduce(sumSize)
} else {
let config = getConfig(files, opts)
let output = path.join(
config.output.path || process.cwd(), config.output.filename)
let size, running
try {
let stats = await runWebpack(config)
if (opts.running !== false) running = await getRunningTime(output)
if (stats.hasErrors()) {
throw new Error(stats.toString('errors-only'))
}
if (opts.config && stats.stats) {
size = stats.stats
.map(stat => extractSize(stat.toJson(), opts))
.reduce(sumSize)
} else {
size = extractSize(stats.toJson(), opts)
}
} finally {
if (config.output.path && !opts.output) {
await del(config.output.path, { force: true })
}
}
let result = { parsed: size.parsed - WEBPACK_EMPTY_PROJECT_PARSED }
if (opts.running !== false) result.running = running
if (opts.config || opts.gzip === false) {
result.loading = getLoadingTime(result.parsed)
} else {
result.gzip = size.gzip - WEBPACK_EMPTY_PROJECT_GZIP
result.loading = getLoadingTime(result.gzip)
}
return result
}
} | [
"async",
"function",
"getSize",
"(",
"files",
",",
"opts",
")",
"{",
"if",
"(",
"typeof",
"files",
"===",
"'string'",
")",
"files",
"=",
"[",
"files",
"]",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
"if",
"(",
"opts",
".",
"webpack",
"===",
"false",
")",
"{",
"let",
"sizes",
"=",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"async",
"file",
"=>",
"{",
"let",
"bytes",
"=",
"await",
"readFile",
"(",
"file",
",",
"'utf8'",
")",
"let",
"result",
"=",
"{",
"parsed",
":",
"bytes",
".",
"length",
"}",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"result",
".",
"running",
"=",
"await",
"getRunningTime",
"(",
"file",
")",
"if",
"(",
"opts",
".",
"gzip",
"===",
"false",
")",
"{",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"parsed",
")",
"}",
"else",
"{",
"result",
".",
"gzip",
"=",
"await",
"gzipSize",
"(",
"bytes",
")",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"gzip",
")",
"}",
"return",
"result",
"}",
")",
")",
"return",
"sizes",
".",
"reduce",
"(",
"sumSize",
")",
"}",
"else",
"{",
"let",
"config",
"=",
"getConfig",
"(",
"files",
",",
"opts",
")",
"let",
"output",
"=",
"path",
".",
"join",
"(",
"config",
".",
"output",
".",
"path",
"||",
"process",
".",
"cwd",
"(",
")",
",",
"config",
".",
"output",
".",
"filename",
")",
"let",
"size",
",",
"running",
"try",
"{",
"let",
"stats",
"=",
"await",
"runWebpack",
"(",
"config",
")",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"running",
"=",
"await",
"getRunningTime",
"(",
"output",
")",
"if",
"(",
"stats",
".",
"hasErrors",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"stats",
".",
"toString",
"(",
"'errors-only'",
")",
")",
"}",
"if",
"(",
"opts",
".",
"config",
"&&",
"stats",
".",
"stats",
")",
"{",
"size",
"=",
"stats",
".",
"stats",
".",
"map",
"(",
"stat",
"=>",
"extractSize",
"(",
"stat",
".",
"toJson",
"(",
")",
",",
"opts",
")",
")",
".",
"reduce",
"(",
"sumSize",
")",
"}",
"else",
"{",
"size",
"=",
"extractSize",
"(",
"stats",
".",
"toJson",
"(",
")",
",",
"opts",
")",
"}",
"}",
"finally",
"{",
"if",
"(",
"config",
".",
"output",
".",
"path",
"&&",
"!",
"opts",
".",
"output",
")",
"{",
"await",
"del",
"(",
"config",
".",
"output",
".",
"path",
",",
"{",
"force",
":",
"true",
"}",
")",
"}",
"}",
"let",
"result",
"=",
"{",
"parsed",
":",
"size",
".",
"parsed",
"-",
"WEBPACK_EMPTY_PROJECT_PARSED",
"}",
"if",
"(",
"opts",
".",
"running",
"!==",
"false",
")",
"result",
".",
"running",
"=",
"running",
"if",
"(",
"opts",
".",
"config",
"||",
"opts",
".",
"gzip",
"===",
"false",
")",
"{",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"parsed",
")",
"}",
"else",
"{",
"result",
".",
"gzip",
"=",
"size",
".",
"gzip",
"-",
"WEBPACK_EMPTY_PROJECT_GZIP",
"result",
".",
"loading",
"=",
"getLoadingTime",
"(",
"result",
".",
"gzip",
")",
"}",
"return",
"result",
"}",
"}"
] | Return size of project files with all dependencies and after UglifyJS
and gzip.
@param {string|string[]} files Files to get size.
@param {object} [opts] Extra options.
@param {"server"|"static"|false} [opts.analyzer=false] Show package
content in browser.
@param {boolean} [opts.webpack=true] Pack files by webpack.
@param {boolean} [opts.running=true] Calculate running time.
@param {boolean} [opts.gzip=true] Compress files by gzip.
@param {string} [opts.config] A path to custom webpack config.
@param {string} [opts.bundle] Bundle name for Analyzer mode.
@param {string} [opts.output] A path for output bundle.
@param {string[]} [opts.ignore] Dependencies to be ignored.
@param {string[]} [opts.entry] Webpack entry whose size will be checked.
@return {Promise} Promise with parsed and gzip size of files
@example
const getSize = require('size-limit')
const index = path.join(__dirname, 'index.js')
const extra = path.join(__dirname, 'extra.js')
getSize([index, extra]).then(size => {
if (size.gzip > 1 * 1024 * 1024) {
console.error('Project become bigger than 1MB')
}
}) | [
"Return",
"size",
"of",
"project",
"files",
"with",
"all",
"dependencies",
"and",
"after",
"UglifyJS",
"and",
"gzip",
"."
] | 0795111fe22771a7e7b82ab95f8e2e43f08dc2cf | https://github.com/ai/size-limit/blob/0795111fe22771a7e7b82ab95f8e2e43f08dc2cf/index.js#L212-L266 |
3,658 | zeit/now-cli | src/commands/inspect.js | getEventMetadata | function getEventMetadata({ event, payload }) {
if (event === 'state') {
return chalk.bold(payload.value);
}
if (event === 'instance-start' || event === 'instance-stop') {
if (payload.dc != null) {
return chalk.green(`(${payload.dc})`);
}
}
return '';
} | javascript | function getEventMetadata({ event, payload }) {
if (event === 'state') {
return chalk.bold(payload.value);
}
if (event === 'instance-start' || event === 'instance-stop') {
if (payload.dc != null) {
return chalk.green(`(${payload.dc})`);
}
}
return '';
} | [
"function",
"getEventMetadata",
"(",
"{",
"event",
",",
"payload",
"}",
")",
"{",
"if",
"(",
"event",
"===",
"'state'",
")",
"{",
"return",
"chalk",
".",
"bold",
"(",
"payload",
".",
"value",
")",
";",
"}",
"if",
"(",
"event",
"===",
"'instance-start'",
"||",
"event",
"===",
"'instance-stop'",
")",
"{",
"if",
"(",
"payload",
".",
"dc",
"!=",
"null",
")",
"{",
"return",
"chalk",
".",
"green",
"(",
"`",
"${",
"payload",
".",
"dc",
"}",
"`",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | gets the metadata that should be printed next to each event | [
"gets",
"the",
"metadata",
"that",
"should",
"be",
"printed",
"next",
"to",
"each",
"event"
] | b53d907b745126113bc3e251ac2451088026a363 | https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/inspect.js#L286-L298 |
3,659 | zeit/now-cli | src/commands/inspect.js | stateString | function stateString(s) {
switch (s) {
case 'INITIALIZING':
return chalk.yellow(s);
case 'ERROR':
return chalk.red(s);
case 'READY':
return s;
default:
return chalk.gray('UNKNOWN');
}
} | javascript | function stateString(s) {
switch (s) {
case 'INITIALIZING':
return chalk.yellow(s);
case 'ERROR':
return chalk.red(s);
case 'READY':
return s;
default:
return chalk.gray('UNKNOWN');
}
} | [
"function",
"stateString",
"(",
"s",
")",
"{",
"switch",
"(",
"s",
")",
"{",
"case",
"'INITIALIZING'",
":",
"return",
"chalk",
".",
"yellow",
"(",
"s",
")",
";",
"case",
"'ERROR'",
":",
"return",
"chalk",
".",
"red",
"(",
"s",
")",
";",
"case",
"'READY'",
":",
"return",
"s",
";",
"default",
":",
"return",
"chalk",
".",
"gray",
"(",
"'UNKNOWN'",
")",
";",
"}",
"}"
] | renders the state string | [
"renders",
"the",
"state",
"string"
] | b53d907b745126113bc3e251ac2451088026a363 | https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/inspect.js#L309-L323 |
3,660 | zeit/now-cli | src/commands/list.js | filterUniqueApps | function filterUniqueApps() {
const uniqueApps = new Set();
return function uniqueAppFilter([appName]) {
if (uniqueApps.has(appName)) {
return false;
}
uniqueApps.add(appName);
return true;
};
} | javascript | function filterUniqueApps() {
const uniqueApps = new Set();
return function uniqueAppFilter([appName]) {
if (uniqueApps.has(appName)) {
return false;
}
uniqueApps.add(appName);
return true;
};
} | [
"function",
"filterUniqueApps",
"(",
")",
"{",
"const",
"uniqueApps",
"=",
"new",
"Set",
"(",
")",
";",
"return",
"function",
"uniqueAppFilter",
"(",
"[",
"appName",
"]",
")",
"{",
"if",
"(",
"uniqueApps",
".",
"has",
"(",
"appName",
")",
")",
"{",
"return",
"false",
";",
"}",
"uniqueApps",
".",
"add",
"(",
"appName",
")",
";",
"return",
"true",
";",
"}",
";",
"}"
] | filters only one deployment per app, so that the user doesn't see so many deployments at once. this mode can be bypassed by supplying an app name | [
"filters",
"only",
"one",
"deployment",
"per",
"app",
"so",
"that",
"the",
"user",
"doesn",
"t",
"see",
"so",
"many",
"deployments",
"at",
"once",
".",
"this",
"mode",
"can",
"be",
"bypassed",
"by",
"supplying",
"an",
"app",
"name"
] | b53d907b745126113bc3e251ac2451088026a363 | https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/commands/list.js#L337-L346 |
3,661 | zeit/now-cli | src/util/hash.js | hashes | async function hashes(files) {
const map = new Map();
await Promise.all(
files.map(async name => {
const data = await fs.promises.readFile(name);
const h = hash(data);
const entry = map.get(h);
if (entry) {
entry.names.push(name);
} else {
map.set(hash(data), { names: [name], data });
}
})
);
return map;
} | javascript | async function hashes(files) {
const map = new Map();
await Promise.all(
files.map(async name => {
const data = await fs.promises.readFile(name);
const h = hash(data);
const entry = map.get(h);
if (entry) {
entry.names.push(name);
} else {
map.set(hash(data), { names: [name], data });
}
})
);
return map;
} | [
"async",
"function",
"hashes",
"(",
"files",
")",
"{",
"const",
"map",
"=",
"new",
"Map",
"(",
")",
";",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"async",
"name",
"=>",
"{",
"const",
"data",
"=",
"await",
"fs",
".",
"promises",
".",
"readFile",
"(",
"name",
")",
";",
"const",
"h",
"=",
"hash",
"(",
"data",
")",
";",
"const",
"entry",
"=",
"map",
".",
"get",
"(",
"h",
")",
";",
"if",
"(",
"entry",
")",
"{",
"entry",
".",
"names",
".",
"push",
"(",
"name",
")",
";",
"}",
"else",
"{",
"map",
".",
"set",
"(",
"hash",
"(",
"data",
")",
",",
"{",
"names",
":",
"[",
"name",
"]",
",",
"data",
"}",
")",
";",
"}",
"}",
")",
")",
";",
"return",
"map",
";",
"}"
] | Computes hashes for the contents of each file given.
@param {Array} of {String} full paths
@return {Map} | [
"Computes",
"hashes",
"for",
"the",
"contents",
"of",
"each",
"file",
"given",
"."
] | b53d907b745126113bc3e251ac2451088026a363 | https://github.com/zeit/now-cli/blob/b53d907b745126113bc3e251ac2451088026a363/src/util/hash.js#L14-L31 |
3,662 | Freeboard/freeboard | js/freeboard.thirdparty.js | function( element ) {
// if the element is already wrapped, return it
if ( element.parent().is( ".ui-effects-wrapper" )) {
return element.parent();
}
// wrap the element
var props = {
width: element.outerWidth(true),
height: element.outerHeight(true),
"float": element.css( "float" )
},
wrapper = $( "<div></div>" )
.addClass( "ui-effects-wrapper" )
.css({
fontSize: "100%",
background: "transparent",
border: "none",
margin: 0,
padding: 0
}),
// Store the size in case width/height are defined in % - Fixes #5245
size = {
width: element.width(),
height: element.height()
},
active = document.activeElement;
// support: Firefox
// Firefox incorrectly exposes anonymous content
// https://bugzilla.mozilla.org/show_bug.cgi?id=561664
try {
active.id;
} catch( e ) {
active = document.body;
}
element.wrap( wrapper );
// Fixes #7595 - Elements lose focus when wrapped.
if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
$( active ).focus();
}
wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
// transfer positioning properties to the wrapper
if ( element.css( "position" ) === "static" ) {
wrapper.css({ position: "relative" });
element.css({ position: "relative" });
} else {
$.extend( props, {
position: element.css( "position" ),
zIndex: element.css( "z-index" )
});
$.each([ "top", "left", "bottom", "right" ], function(i, pos) {
props[ pos ] = element.css( pos );
if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
props[ pos ] = "auto";
}
});
element.css({
position: "relative",
top: 0,
left: 0,
right: "auto",
bottom: "auto"
});
}
element.css(size);
return wrapper.css( props ).show();
} | javascript | function( element ) {
// if the element is already wrapped, return it
if ( element.parent().is( ".ui-effects-wrapper" )) {
return element.parent();
}
// wrap the element
var props = {
width: element.outerWidth(true),
height: element.outerHeight(true),
"float": element.css( "float" )
},
wrapper = $( "<div></div>" )
.addClass( "ui-effects-wrapper" )
.css({
fontSize: "100%",
background: "transparent",
border: "none",
margin: 0,
padding: 0
}),
// Store the size in case width/height are defined in % - Fixes #5245
size = {
width: element.width(),
height: element.height()
},
active = document.activeElement;
// support: Firefox
// Firefox incorrectly exposes anonymous content
// https://bugzilla.mozilla.org/show_bug.cgi?id=561664
try {
active.id;
} catch( e ) {
active = document.body;
}
element.wrap( wrapper );
// Fixes #7595 - Elements lose focus when wrapped.
if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
$( active ).focus();
}
wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
// transfer positioning properties to the wrapper
if ( element.css( "position" ) === "static" ) {
wrapper.css({ position: "relative" });
element.css({ position: "relative" });
} else {
$.extend( props, {
position: element.css( "position" ),
zIndex: element.css( "z-index" )
});
$.each([ "top", "left", "bottom", "right" ], function(i, pos) {
props[ pos ] = element.css( pos );
if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
props[ pos ] = "auto";
}
});
element.css({
position: "relative",
top: 0,
left: 0,
right: "auto",
bottom: "auto"
});
}
element.css(size);
return wrapper.css( props ).show();
} | [
"function",
"(",
"element",
")",
"{",
"// if the element is already wrapped, return it",
"if",
"(",
"element",
".",
"parent",
"(",
")",
".",
"is",
"(",
"\".ui-effects-wrapper\"",
")",
")",
"{",
"return",
"element",
".",
"parent",
"(",
")",
";",
"}",
"// wrap the element",
"var",
"props",
"=",
"{",
"width",
":",
"element",
".",
"outerWidth",
"(",
"true",
")",
",",
"height",
":",
"element",
".",
"outerHeight",
"(",
"true",
")",
",",
"\"float\"",
":",
"element",
".",
"css",
"(",
"\"float\"",
")",
"}",
",",
"wrapper",
"=",
"$",
"(",
"\"<div></div>\"",
")",
".",
"addClass",
"(",
"\"ui-effects-wrapper\"",
")",
".",
"css",
"(",
"{",
"fontSize",
":",
"\"100%\"",
",",
"background",
":",
"\"transparent\"",
",",
"border",
":",
"\"none\"",
",",
"margin",
":",
"0",
",",
"padding",
":",
"0",
"}",
")",
",",
"// Store the size in case width/height are defined in % - Fixes #5245",
"size",
"=",
"{",
"width",
":",
"element",
".",
"width",
"(",
")",
",",
"height",
":",
"element",
".",
"height",
"(",
")",
"}",
",",
"active",
"=",
"document",
".",
"activeElement",
";",
"// support: Firefox",
"// Firefox incorrectly exposes anonymous content",
"// https://bugzilla.mozilla.org/show_bug.cgi?id=561664",
"try",
"{",
"active",
".",
"id",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"active",
"=",
"document",
".",
"body",
";",
"}",
"element",
".",
"wrap",
"(",
"wrapper",
")",
";",
"// Fixes #7595 - Elements lose focus when wrapped.",
"if",
"(",
"element",
"[",
"0",
"]",
"===",
"active",
"||",
"$",
".",
"contains",
"(",
"element",
"[",
"0",
"]",
",",
"active",
")",
")",
"{",
"$",
"(",
"active",
")",
".",
"focus",
"(",
")",
";",
"}",
"wrapper",
"=",
"element",
".",
"parent",
"(",
")",
";",
"//Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element",
"// transfer positioning properties to the wrapper",
"if",
"(",
"element",
".",
"css",
"(",
"\"position\"",
")",
"===",
"\"static\"",
")",
"{",
"wrapper",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
"}",
")",
";",
"element",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
"}",
")",
";",
"}",
"else",
"{",
"$",
".",
"extend",
"(",
"props",
",",
"{",
"position",
":",
"element",
".",
"css",
"(",
"\"position\"",
")",
",",
"zIndex",
":",
"element",
".",
"css",
"(",
"\"z-index\"",
")",
"}",
")",
";",
"$",
".",
"each",
"(",
"[",
"\"top\"",
",",
"\"left\"",
",",
"\"bottom\"",
",",
"\"right\"",
"]",
",",
"function",
"(",
"i",
",",
"pos",
")",
"{",
"props",
"[",
"pos",
"]",
"=",
"element",
".",
"css",
"(",
"pos",
")",
";",
"if",
"(",
"isNaN",
"(",
"parseInt",
"(",
"props",
"[",
"pos",
"]",
",",
"10",
")",
")",
")",
"{",
"props",
"[",
"pos",
"]",
"=",
"\"auto\"",
";",
"}",
"}",
")",
";",
"element",
".",
"css",
"(",
"{",
"position",
":",
"\"relative\"",
",",
"top",
":",
"0",
",",
"left",
":",
"0",
",",
"right",
":",
"\"auto\"",
",",
"bottom",
":",
"\"auto\"",
"}",
")",
";",
"}",
"element",
".",
"css",
"(",
"size",
")",
";",
"return",
"wrapper",
".",
"css",
"(",
"props",
")",
".",
"show",
"(",
")",
";",
"}"
] | Wraps the element around a wrapper that copies position properties | [
"Wraps",
"the",
"element",
"around",
"a",
"wrapper",
"that",
"copies",
"position",
"properties"
] | 38789f6e8bd3d04f7d3b2c3427e509d00f2610fc | https://github.com/Freeboard/freeboard/blob/38789f6e8bd3d04f7d3b2c3427e509d00f2610fc/js/freeboard.thirdparty.js#L5734-L5807 |
|
3,663 | Freeboard/freeboard | js/freeboard.thirdparty.js | function( value, allowAny ) {
var parsed;
if ( value !== "" ) {
parsed = this._parse( value );
if ( parsed !== null ) {
if ( !allowAny ) {
parsed = this._adjustValue( parsed );
}
value = this._format( parsed );
}
}
this.element.val( value );
this._refresh();
} | javascript | function( value, allowAny ) {
var parsed;
if ( value !== "" ) {
parsed = this._parse( value );
if ( parsed !== null ) {
if ( !allowAny ) {
parsed = this._adjustValue( parsed );
}
value = this._format( parsed );
}
}
this.element.val( value );
this._refresh();
} | [
"function",
"(",
"value",
",",
"allowAny",
")",
"{",
"var",
"parsed",
";",
"if",
"(",
"value",
"!==",
"\"\"",
")",
"{",
"parsed",
"=",
"this",
".",
"_parse",
"(",
"value",
")",
";",
"if",
"(",
"parsed",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"allowAny",
")",
"{",
"parsed",
"=",
"this",
".",
"_adjustValue",
"(",
"parsed",
")",
";",
"}",
"value",
"=",
"this",
".",
"_format",
"(",
"parsed",
")",
";",
"}",
"}",
"this",
".",
"element",
".",
"val",
"(",
"value",
")",
";",
"this",
".",
"_refresh",
"(",
")",
";",
"}"
] | update the value without triggering change | [
"update",
"the",
"value",
"without",
"triggering",
"change"
] | 38789f6e8bd3d04f7d3b2c3427e509d00f2610fc | https://github.com/Freeboard/freeboard/blob/38789f6e8bd3d04f7d3b2c3427e509d00f2610fc/js/freeboard.thirdparty.js#L13730-L13743 |
|
3,664 | testing-library/dom-testing-library | src/query-helpers.js | makeSingleQuery | function makeSingleQuery(allQuery, getMultipleError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (els.length > 1) {
throw getMultipleElementsFoundError(
getMultipleError(container, ...args),
container,
)
}
return els[0] || null
}
} | javascript | function makeSingleQuery(allQuery, getMultipleError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (els.length > 1) {
throw getMultipleElementsFoundError(
getMultipleError(container, ...args),
container,
)
}
return els[0] || null
}
} | [
"function",
"makeSingleQuery",
"(",
"allQuery",
",",
"getMultipleError",
")",
"{",
"return",
"(",
"container",
",",
"...",
"args",
")",
"=>",
"{",
"const",
"els",
"=",
"allQuery",
"(",
"container",
",",
"...",
"args",
")",
"if",
"(",
"els",
".",
"length",
">",
"1",
")",
"{",
"throw",
"getMultipleElementsFoundError",
"(",
"getMultipleError",
"(",
"container",
",",
"...",
"args",
")",
",",
"container",
",",
")",
"}",
"return",
"els",
"[",
"0",
"]",
"||",
"null",
"}",
"}"
] | this accepts a query function and returns a function which throws an error if more than one elements is returned, otherwise it returns the first element or null | [
"this",
"accepts",
"a",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"throws",
"an",
"error",
"if",
"more",
"than",
"one",
"elements",
"is",
"returned",
"otherwise",
"it",
"returns",
"the",
"first",
"element",
"or",
"null"
] | fcb2cbcffb7aff6ecff3be8731168c86eee82ce1 | https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L68-L79 |
3,665 | testing-library/dom-testing-library | src/query-helpers.js | makeGetAllQuery | function makeGetAllQuery(allQuery, getMissingError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (!els.length) {
throw getElementError(getMissingError(container, ...args), container)
}
return els
}
} | javascript | function makeGetAllQuery(allQuery, getMissingError) {
return (container, ...args) => {
const els = allQuery(container, ...args)
if (!els.length) {
throw getElementError(getMissingError(container, ...args), container)
}
return els
}
} | [
"function",
"makeGetAllQuery",
"(",
"allQuery",
",",
"getMissingError",
")",
"{",
"return",
"(",
"container",
",",
"...",
"args",
")",
"=>",
"{",
"const",
"els",
"=",
"allQuery",
"(",
"container",
",",
"...",
"args",
")",
"if",
"(",
"!",
"els",
".",
"length",
")",
"{",
"throw",
"getElementError",
"(",
"getMissingError",
"(",
"container",
",",
"...",
"args",
")",
",",
"container",
")",
"}",
"return",
"els",
"}",
"}"
] | this accepts a query function and returns a function which throws an error if an empty list of elements is returned | [
"this",
"accepts",
"a",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"throws",
"an",
"error",
"if",
"an",
"empty",
"list",
"of",
"elements",
"is",
"returned"
] | fcb2cbcffb7aff6ecff3be8731168c86eee82ce1 | https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L83-L91 |
3,666 | testing-library/dom-testing-library | src/query-helpers.js | makeFindQuery | function makeFindQuery(getter) {
return (container, text, options, waitForElementOptions) =>
waitForElement(
() => getter(container, text, options),
waitForElementOptions,
)
} | javascript | function makeFindQuery(getter) {
return (container, text, options, waitForElementOptions) =>
waitForElement(
() => getter(container, text, options),
waitForElementOptions,
)
} | [
"function",
"makeFindQuery",
"(",
"getter",
")",
"{",
"return",
"(",
"container",
",",
"text",
",",
"options",
",",
"waitForElementOptions",
")",
"=>",
"waitForElement",
"(",
"(",
")",
"=>",
"getter",
"(",
"container",
",",
"text",
",",
"options",
")",
",",
"waitForElementOptions",
",",
")",
"}"
] | this accepts a getter query function and returns a function which calls waitForElement and passing a function which invokes the getter. | [
"this",
"accepts",
"a",
"getter",
"query",
"function",
"and",
"returns",
"a",
"function",
"which",
"calls",
"waitForElement",
"and",
"passing",
"a",
"function",
"which",
"invokes",
"the",
"getter",
"."
] | fcb2cbcffb7aff6ecff3be8731168c86eee82ce1 | https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/query-helpers.js#L95-L101 |
3,667 | testing-library/dom-testing-library | src/matches.js | makeNormalizer | function makeNormalizer({trim, collapseWhitespace, normalizer}) {
if (normalizer) {
// User has specified a custom normalizer
if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}
return normalizer
} else {
// No custom normalizer specified. Just use default.
return getDefaultNormalizer({trim, collapseWhitespace})
}
} | javascript | function makeNormalizer({trim, collapseWhitespace, normalizer}) {
if (normalizer) {
// User has specified a custom normalizer
if (
typeof trim !== 'undefined' ||
typeof collapseWhitespace !== 'undefined'
) {
// They've also specified a value for trim or collapseWhitespace
throw new Error(
'trim and collapseWhitespace are not supported with a normalizer. ' +
'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' +
'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer',
)
}
return normalizer
} else {
// No custom normalizer specified. Just use default.
return getDefaultNormalizer({trim, collapseWhitespace})
}
} | [
"function",
"makeNormalizer",
"(",
"{",
"trim",
",",
"collapseWhitespace",
",",
"normalizer",
"}",
")",
"{",
"if",
"(",
"normalizer",
")",
"{",
"// User has specified a custom normalizer",
"if",
"(",
"typeof",
"trim",
"!==",
"'undefined'",
"||",
"typeof",
"collapseWhitespace",
"!==",
"'undefined'",
")",
"{",
"// They've also specified a value for trim or collapseWhitespace",
"throw",
"new",
"Error",
"(",
"'trim and collapseWhitespace are not supported with a normalizer. '",
"+",
"'If you want to use the default trim and collapseWhitespace logic in your normalizer, '",
"+",
"'use \"getDefaultNormalizer({trim, collapseWhitespace})\" and compose that into your normalizer'",
",",
")",
"}",
"return",
"normalizer",
"}",
"else",
"{",
"// No custom normalizer specified. Just use default.",
"return",
"getDefaultNormalizer",
"(",
"{",
"trim",
",",
"collapseWhitespace",
"}",
")",
"}",
"}"
] | Constructs a normalizer to pass to functions in matches.js
@param {boolean|undefined} trim The user-specified value for `trim`, without
any defaulting having been applied
@param {boolean|undefined} collapseWhitespace The user-specified value for
`collapseWhitespace`, without any defaulting having been applied
@param {Function|undefined} normalizer The user-specified normalizer
@returns {Function} A normalizer | [
"Constructs",
"a",
"normalizer",
"to",
"pass",
"to",
"functions",
"in",
"matches",
".",
"js"
] | fcb2cbcffb7aff6ecff3be8731168c86eee82ce1 | https://github.com/testing-library/dom-testing-library/blob/fcb2cbcffb7aff6ecff3be8731168c86eee82ce1/src/matches.js#L51-L71 |
3,668 | muaz-khan/RecordRTC | RecordRTC.js | function(arrayOfWebPImages) {
config.advertisement = [];
var length = arrayOfWebPImages.length;
for (var i = 0; i < length; i++) {
config.advertisement.push({
duration: i,
image: arrayOfWebPImages[i]
});
}
} | javascript | function(arrayOfWebPImages) {
config.advertisement = [];
var length = arrayOfWebPImages.length;
for (var i = 0; i < length; i++) {
config.advertisement.push({
duration: i,
image: arrayOfWebPImages[i]
});
}
} | [
"function",
"(",
"arrayOfWebPImages",
")",
"{",
"config",
".",
"advertisement",
"=",
"[",
"]",
";",
"var",
"length",
"=",
"arrayOfWebPImages",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"config",
".",
"advertisement",
".",
"push",
"(",
"{",
"duration",
":",
"i",
",",
"image",
":",
"arrayOfWebPImages",
"[",
"i",
"]",
"}",
")",
";",
"}",
"}"
] | This method appends an array of webp images to the recorded video-blob. It takes an "array" object.
@type {Array.<Array>}
@param {Array} arrayOfWebPImages - Array of webp images.
@method
@memberof RecordRTC
@instance
@todo This method should be deprecated.
@example
var arrayOfWebPImages = [];
arrayOfWebPImages.push({
duration: index,
image: 'data:image/webp;base64,...'
});
recorder.setAdvertisementArray(arrayOfWebPImages); | [
"This",
"method",
"appends",
"an",
"array",
"of",
"webp",
"images",
"to",
"the",
"recorded",
"video",
"-",
"blob",
".",
"It",
"takes",
"an",
"array",
"object",
"."
] | 3c6bad427b9da35c1cf617199ed13dda056c38ba | https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L606-L616 |
|
3,669 | muaz-khan/RecordRTC | RecordRTC.js | function() {
if (mediaRecorder && typeof mediaRecorder.clearRecordedData === 'function') {
mediaRecorder.clearRecordedData();
}
mediaRecorder = null;
setState('inactive');
self.blob = null;
} | javascript | function() {
if (mediaRecorder && typeof mediaRecorder.clearRecordedData === 'function') {
mediaRecorder.clearRecordedData();
}
mediaRecorder = null;
setState('inactive');
self.blob = null;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"mediaRecorder",
"&&",
"typeof",
"mediaRecorder",
".",
"clearRecordedData",
"===",
"'function'",
")",
"{",
"mediaRecorder",
".",
"clearRecordedData",
"(",
")",
";",
"}",
"mediaRecorder",
"=",
"null",
";",
"setState",
"(",
"'inactive'",
")",
";",
"self",
".",
"blob",
"=",
"null",
";",
"}"
] | This method resets the recorder. So that you can reuse single recorder instance many times.
@method
@memberof RecordRTC
@instance
@example
recorder.reset();
recorder.startRecording(); | [
"This",
"method",
"resets",
"the",
"recorder",
".",
"So",
"that",
"you",
"can",
"reuse",
"single",
"recorder",
"instance",
"many",
"times",
"."
] | 3c6bad427b9da35c1cf617199ed13dda056c38ba | https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L683-L690 |
|
3,670 | muaz-khan/RecordRTC | RecordRTC.js | function() {
var self = this;
if (typeof indexedDB === 'undefined' || typeof indexedDB.open === 'undefined') {
console.error('IndexedDB API are not available in this browser.');
return;
}
var dbVersion = 1;
var dbName = this.dbName || location.href.replace(/\/|:|#|%|\.|\[|\]/g, ''),
db;
var request = indexedDB.open(dbName, dbVersion);
function createObjectStore(dataBase) {
dataBase.createObjectStore(self.dataStoreName);
}
function putInDB() {
var transaction = db.transaction([self.dataStoreName], 'readwrite');
if (self.videoBlob) {
transaction.objectStore(self.dataStoreName).put(self.videoBlob, 'videoBlob');
}
if (self.gifBlob) {
transaction.objectStore(self.dataStoreName).put(self.gifBlob, 'gifBlob');
}
if (self.audioBlob) {
transaction.objectStore(self.dataStoreName).put(self.audioBlob, 'audioBlob');
}
function getFromStore(portionName) {
transaction.objectStore(self.dataStoreName).get(portionName).onsuccess = function(event) {
if (self.callback) {
self.callback(event.target.result, portionName);
}
};
}
getFromStore('audioBlob');
getFromStore('videoBlob');
getFromStore('gifBlob');
}
request.onerror = self.onError;
request.onsuccess = function() {
db = request.result;
db.onerror = self.onError;
if (db.setVersion) {
if (db.version !== dbVersion) {
var setVersion = db.setVersion(dbVersion);
setVersion.onsuccess = function() {
createObjectStore(db);
putInDB();
};
} else {
putInDB();
}
} else {
putInDB();
}
};
request.onupgradeneeded = function(event) {
createObjectStore(event.target.result);
};
} | javascript | function() {
var self = this;
if (typeof indexedDB === 'undefined' || typeof indexedDB.open === 'undefined') {
console.error('IndexedDB API are not available in this browser.');
return;
}
var dbVersion = 1;
var dbName = this.dbName || location.href.replace(/\/|:|#|%|\.|\[|\]/g, ''),
db;
var request = indexedDB.open(dbName, dbVersion);
function createObjectStore(dataBase) {
dataBase.createObjectStore(self.dataStoreName);
}
function putInDB() {
var transaction = db.transaction([self.dataStoreName], 'readwrite');
if (self.videoBlob) {
transaction.objectStore(self.dataStoreName).put(self.videoBlob, 'videoBlob');
}
if (self.gifBlob) {
transaction.objectStore(self.dataStoreName).put(self.gifBlob, 'gifBlob');
}
if (self.audioBlob) {
transaction.objectStore(self.dataStoreName).put(self.audioBlob, 'audioBlob');
}
function getFromStore(portionName) {
transaction.objectStore(self.dataStoreName).get(portionName).onsuccess = function(event) {
if (self.callback) {
self.callback(event.target.result, portionName);
}
};
}
getFromStore('audioBlob');
getFromStore('videoBlob');
getFromStore('gifBlob');
}
request.onerror = self.onError;
request.onsuccess = function() {
db = request.result;
db.onerror = self.onError;
if (db.setVersion) {
if (db.version !== dbVersion) {
var setVersion = db.setVersion(dbVersion);
setVersion.onsuccess = function() {
createObjectStore(db);
putInDB();
};
} else {
putInDB();
}
} else {
putInDB();
}
};
request.onupgradeneeded = function(event) {
createObjectStore(event.target.result);
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"typeof",
"indexedDB",
"===",
"'undefined'",
"||",
"typeof",
"indexedDB",
".",
"open",
"===",
"'undefined'",
")",
"{",
"console",
".",
"error",
"(",
"'IndexedDB API are not available in this browser.'",
")",
";",
"return",
";",
"}",
"var",
"dbVersion",
"=",
"1",
";",
"var",
"dbName",
"=",
"this",
".",
"dbName",
"||",
"location",
".",
"href",
".",
"replace",
"(",
"/",
"\\/|:|#|%|\\.|\\[|\\]",
"/",
"g",
",",
"''",
")",
",",
"db",
";",
"var",
"request",
"=",
"indexedDB",
".",
"open",
"(",
"dbName",
",",
"dbVersion",
")",
";",
"function",
"createObjectStore",
"(",
"dataBase",
")",
"{",
"dataBase",
".",
"createObjectStore",
"(",
"self",
".",
"dataStoreName",
")",
";",
"}",
"function",
"putInDB",
"(",
")",
"{",
"var",
"transaction",
"=",
"db",
".",
"transaction",
"(",
"[",
"self",
".",
"dataStoreName",
"]",
",",
"'readwrite'",
")",
";",
"if",
"(",
"self",
".",
"videoBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"videoBlob",
",",
"'videoBlob'",
")",
";",
"}",
"if",
"(",
"self",
".",
"gifBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"gifBlob",
",",
"'gifBlob'",
")",
";",
"}",
"if",
"(",
"self",
".",
"audioBlob",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"put",
"(",
"self",
".",
"audioBlob",
",",
"'audioBlob'",
")",
";",
"}",
"function",
"getFromStore",
"(",
"portionName",
")",
"{",
"transaction",
".",
"objectStore",
"(",
"self",
".",
"dataStoreName",
")",
".",
"get",
"(",
"portionName",
")",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"self",
".",
"callback",
")",
"{",
"self",
".",
"callback",
"(",
"event",
".",
"target",
".",
"result",
",",
"portionName",
")",
";",
"}",
"}",
";",
"}",
"getFromStore",
"(",
"'audioBlob'",
")",
";",
"getFromStore",
"(",
"'videoBlob'",
")",
";",
"getFromStore",
"(",
"'gifBlob'",
")",
";",
"}",
"request",
".",
"onerror",
"=",
"self",
".",
"onError",
";",
"request",
".",
"onsuccess",
"=",
"function",
"(",
")",
"{",
"db",
"=",
"request",
".",
"result",
";",
"db",
".",
"onerror",
"=",
"self",
".",
"onError",
";",
"if",
"(",
"db",
".",
"setVersion",
")",
"{",
"if",
"(",
"db",
".",
"version",
"!==",
"dbVersion",
")",
"{",
"var",
"setVersion",
"=",
"db",
".",
"setVersion",
"(",
"dbVersion",
")",
";",
"setVersion",
".",
"onsuccess",
"=",
"function",
"(",
")",
"{",
"createObjectStore",
"(",
"db",
")",
";",
"putInDB",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"putInDB",
"(",
")",
";",
"}",
"}",
"else",
"{",
"putInDB",
"(",
")",
";",
"}",
"}",
";",
"request",
".",
"onupgradeneeded",
"=",
"function",
"(",
"event",
")",
"{",
"createObjectStore",
"(",
"event",
".",
"target",
".",
"result",
")",
";",
"}",
";",
"}"
] | This method must be called once to initialize IndexedDB ObjectStore. Though, it is auto-used internally.
@method
@memberof DiskStorage
@internal
@example
DiskStorage.init(); | [
"This",
"method",
"must",
"be",
"called",
"once",
"to",
"initialize",
"IndexedDB",
"ObjectStore",
".",
"Though",
"it",
"is",
"auto",
"-",
"used",
"internally",
"."
] | 3c6bad427b9da35c1cf617199ed13dda056c38ba | https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L4388-L4456 |
|
3,671 | muaz-khan/RecordRTC | RecordRTC.js | function(config) {
this.audioBlob = config.audioBlob;
this.videoBlob = config.videoBlob;
this.gifBlob = config.gifBlob;
this.init();
return this;
} | javascript | function(config) {
this.audioBlob = config.audioBlob;
this.videoBlob = config.videoBlob;
this.gifBlob = config.gifBlob;
this.init();
return this;
} | [
"function",
"(",
"config",
")",
"{",
"this",
".",
"audioBlob",
"=",
"config",
".",
"audioBlob",
";",
"this",
".",
"videoBlob",
"=",
"config",
".",
"videoBlob",
";",
"this",
".",
"gifBlob",
"=",
"config",
".",
"gifBlob",
";",
"this",
".",
"init",
"(",
")",
";",
"return",
"this",
";",
"}"
] | This method stores blobs in IndexedDB.
@method
@memberof DiskStorage
@internal
@example
DiskStorage.Store({
audioBlob: yourAudioBlob,
videoBlob: yourVideoBlob,
gifBlob : yourGifBlob
}); | [
"This",
"method",
"stores",
"blobs",
"in",
"IndexedDB",
"."
] | 3c6bad427b9da35c1cf617199ed13dda056c38ba | https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/RecordRTC.js#L4487-L4495 |
|
3,672 | muaz-khan/RecordRTC | WebGL-Recording/vendor/glge-compiled.js | getLastNumber | function getLastNumber(str){
var retval="";
for (var i=str.length-1;i>=0;--i)
if (str[i]>="0"&&str[i]<="9")
retval=str[i]+retval;
if (retval.length==0) return "0";
return retval;
} | javascript | function getLastNumber(str){
var retval="";
for (var i=str.length-1;i>=0;--i)
if (str[i]>="0"&&str[i]<="9")
retval=str[i]+retval;
if (retval.length==0) return "0";
return retval;
} | [
"function",
"getLastNumber",
"(",
"str",
")",
"{",
"var",
"retval",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"str",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"if",
"(",
"str",
"[",
"i",
"]",
">=",
"\"0\"",
"&&",
"str",
"[",
"i",
"]",
"<=",
"\"9\"",
")",
"retval",
"=",
"str",
"[",
"i",
"]",
"+",
"retval",
";",
"if",
"(",
"retval",
".",
"length",
"==",
"0",
")",
"return",
"\"0\"",
";",
"return",
"retval",
";",
"}"
] | the exporter is buggy eg VCGLab | MeshLab and does not specify input_set | [
"the",
"exporter",
"is",
"buggy",
"eg",
"VCGLab",
"|",
"MeshLab",
"and",
"does",
"not",
"specify",
"input_set"
] | 3c6bad427b9da35c1cf617199ed13dda056c38ba | https://github.com/muaz-khan/RecordRTC/blob/3c6bad427b9da35c1cf617199ed13dda056c38ba/WebGL-Recording/vendor/glge-compiled.js#L18122-L18129 |
3,673 | statsd/statsd | lib/mgmt_console.js | existing_stats | function existing_stats(stats_type, bucket){
matches = [];
//typical case: one-off, fully qualified
if (bucket in stats_type) {
matches.push(bucket);
}
//special case: match a whole 'folder' (and subfolders) of stats
if (bucket.slice(-2) == ".*") {
var folder = bucket.slice(0,-1);
for (var name in stats_type) {
//check if stat is in bucket, ie~ name starts with folder
if (name.substring(0, folder.length) == folder) {
matches.push(name);
}
}
}
return matches;
} | javascript | function existing_stats(stats_type, bucket){
matches = [];
//typical case: one-off, fully qualified
if (bucket in stats_type) {
matches.push(bucket);
}
//special case: match a whole 'folder' (and subfolders) of stats
if (bucket.slice(-2) == ".*") {
var folder = bucket.slice(0,-1);
for (var name in stats_type) {
//check if stat is in bucket, ie~ name starts with folder
if (name.substring(0, folder.length) == folder) {
matches.push(name);
}
}
}
return matches;
} | [
"function",
"existing_stats",
"(",
"stats_type",
",",
"bucket",
")",
"{",
"matches",
"=",
"[",
"]",
";",
"//typical case: one-off, fully qualified",
"if",
"(",
"bucket",
"in",
"stats_type",
")",
"{",
"matches",
".",
"push",
"(",
"bucket",
")",
";",
"}",
"//special case: match a whole 'folder' (and subfolders) of stats",
"if",
"(",
"bucket",
".",
"slice",
"(",
"-",
"2",
")",
"==",
"\".*\"",
")",
"{",
"var",
"folder",
"=",
"bucket",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
";",
"for",
"(",
"var",
"name",
"in",
"stats_type",
")",
"{",
"//check if stat is in bucket, ie~ name starts with folder",
"if",
"(",
"name",
".",
"substring",
"(",
"0",
",",
"folder",
".",
"length",
")",
"==",
"folder",
")",
"{",
"matches",
".",
"push",
"(",
"name",
")",
";",
"}",
"}",
"}",
"return",
"matches",
";",
"}"
] | existing_stats - find fully qualified matches for the requested stats bucket
@param stats_type array of all statistics of this type (eg~ timers) to match
@param bucket string to search on, which can be fully qualified,
or end in a .* to search for a folder, like stats.temp.*
@return array of fully qualified stats that match the specified bucket. if
no matches, an empty array is a valid response | [
"existing_stats",
"-",
"find",
"fully",
"qualified",
"matches",
"for",
"the",
"requested",
"stats",
"bucket"
] | ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9 | https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/lib/mgmt_console.js#L46-L67 |
3,674 | statsd/statsd | backends/graphite.js | Metric | function Metric(key, value, ts) {
var m = this;
this.key = key;
this.value = value;
this.ts = ts;
// return a string representation of this metric appropriate
// for sending to the graphite collector. does not include
// a trailing newline.
this.toText = function() {
return m.key + " " + m.value + " " + m.ts;
};
this.toPickle = function() {
return MARK + STRING + '\'' + m.key + '\'\n' + MARK + LONG + m.ts + 'L\n' + STRING + '\'' + m.value + '\'\n' + TUPLE + TUPLE + APPEND;
};
} | javascript | function Metric(key, value, ts) {
var m = this;
this.key = key;
this.value = value;
this.ts = ts;
// return a string representation of this metric appropriate
// for sending to the graphite collector. does not include
// a trailing newline.
this.toText = function() {
return m.key + " " + m.value + " " + m.ts;
};
this.toPickle = function() {
return MARK + STRING + '\'' + m.key + '\'\n' + MARK + LONG + m.ts + 'L\n' + STRING + '\'' + m.value + '\'\n' + TUPLE + TUPLE + APPEND;
};
} | [
"function",
"Metric",
"(",
"key",
",",
"value",
",",
"ts",
")",
"{",
"var",
"m",
"=",
"this",
";",
"this",
".",
"key",
"=",
"key",
";",
"this",
".",
"value",
"=",
"value",
";",
"this",
".",
"ts",
"=",
"ts",
";",
"// return a string representation of this metric appropriate ",
"// for sending to the graphite collector. does not include",
"// a trailing newline.",
"this",
".",
"toText",
"=",
"function",
"(",
")",
"{",
"return",
"m",
".",
"key",
"+",
"\" \"",
"+",
"m",
".",
"value",
"+",
"\" \"",
"+",
"m",
".",
"ts",
";",
"}",
";",
"this",
".",
"toPickle",
"=",
"function",
"(",
")",
"{",
"return",
"MARK",
"+",
"STRING",
"+",
"'\\''",
"+",
"m",
".",
"key",
"+",
"'\\'\\n'",
"+",
"MARK",
"+",
"LONG",
"+",
"m",
".",
"ts",
"+",
"'L\\n'",
"+",
"STRING",
"+",
"'\\''",
"+",
"m",
".",
"value",
"+",
"'\\'\\n'",
"+",
"TUPLE",
"+",
"TUPLE",
"+",
"APPEND",
";",
"}",
";",
"}"
] | A single measurement for sending to graphite. | [
"A",
"single",
"measurement",
"for",
"sending",
"to",
"graphite",
"."
] | ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9 | https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L105-L121 |
3,675 | statsd/statsd | backends/graphite.js | Stats | function Stats() {
var s = this;
this.metrics = [];
this.add = function(key, value, ts) {
s.metrics.push(new Metric(key, value, ts));
};
this.toText = function() {
return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
};
this.toPickle = function() {
var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;
// The first four bytes of the graphite pickle format
// contain the length of the rest of the payload.
// We use Buffer because this is binary data.
var buf = new Buffer(4 + body.length);
buf.writeUInt32BE(body.length,0);
buf.write(body,4);
return buf;
};
} | javascript | function Stats() {
var s = this;
this.metrics = [];
this.add = function(key, value, ts) {
s.metrics.push(new Metric(key, value, ts));
};
this.toText = function() {
return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
};
this.toPickle = function() {
var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;
// The first four bytes of the graphite pickle format
// contain the length of the rest of the payload.
// We use Buffer because this is binary data.
var buf = new Buffer(4 + body.length);
buf.writeUInt32BE(body.length,0);
buf.write(body,4);
return buf;
};
} | [
"function",
"Stats",
"(",
")",
"{",
"var",
"s",
"=",
"this",
";",
"this",
".",
"metrics",
"=",
"[",
"]",
";",
"this",
".",
"add",
"=",
"function",
"(",
"key",
",",
"value",
",",
"ts",
")",
"{",
"s",
".",
"metrics",
".",
"push",
"(",
"new",
"Metric",
"(",
"key",
",",
"value",
",",
"ts",
")",
")",
";",
"}",
";",
"this",
".",
"toText",
"=",
"function",
"(",
")",
"{",
"return",
"s",
".",
"metrics",
".",
"map",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"toText",
"(",
")",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
"+",
"'\\n'",
";",
"}",
";",
"this",
".",
"toPickle",
"=",
"function",
"(",
")",
"{",
"var",
"body",
"=",
"MARK",
"+",
"LIST",
"+",
"s",
".",
"metrics",
".",
"map",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"toPickle",
"(",
")",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
"+",
"STOP",
";",
"// The first four bytes of the graphite pickle format",
"// contain the length of the rest of the payload.",
"// We use Buffer because this is binary data.",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"4",
"+",
"body",
".",
"length",
")",
";",
"buf",
".",
"writeUInt32BE",
"(",
"body",
".",
"length",
",",
"0",
")",
";",
"buf",
".",
"write",
"(",
"body",
",",
"4",
")",
";",
"return",
"buf",
";",
"}",
";",
"}"
] | A collection of measurements for sending to graphite. | [
"A",
"collection",
"of",
"measurements",
"for",
"sending",
"to",
"graphite",
"."
] | ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9 | https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L124-L148 |
3,676 | statsd/statsd | backends/graphite.js | sk | function sk(key) {
if (globalKeySanitize) {
return key;
} else {
return key.replace(/\s+/g, '_')
.replace(/\//g, '-')
.replace(/[^a-zA-Z_\-0-9\.]/g, '');
}
} | javascript | function sk(key) {
if (globalKeySanitize) {
return key;
} else {
return key.replace(/\s+/g, '_')
.replace(/\//g, '-')
.replace(/[^a-zA-Z_\-0-9\.]/g, '');
}
} | [
"function",
"sk",
"(",
"key",
")",
"{",
"if",
"(",
"globalKeySanitize",
")",
"{",
"return",
"key",
";",
"}",
"else",
"{",
"return",
"key",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'_'",
")",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'-'",
")",
".",
"replace",
"(",
"/",
"[^a-zA-Z_\\-0-9\\.]",
"/",
"g",
",",
"''",
")",
";",
"}",
"}"
] | Sanitize key for graphite if not done globally | [
"Sanitize",
"key",
"for",
"graphite",
"if",
"not",
"done",
"globally"
] | ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9 | https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/backends/graphite.js#L164-L172 |
3,677 | statsd/statsd | proxy.js | healthcheck | function healthcheck(node) {
var ended = false;
var node_id = node.host + ':' + node.port;
var client = net.connect(
{port: node.adminport, host: node.host},
function onConnect() {
if (!ended) {
client.write('health\r\n');
}
}
);
client.setTimeout(healthCheckInterval, function() {
client.end();
markNodeAsUnhealthy(node_id);
client.removeAllListeners('data');
ended = true;
});
client.on('data', function(data) {
if (ended) {
return;
}
var health_status = data.toString();
client.end();
ended = true;
if (health_status.indexOf('up') < 0) {
markNodeAsUnhealthy(node_id);
} else {
markNodeAsHealthy(node_id);
}
});
client.on('error', function(e) {
if (ended) {
return;
}
if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
}
markNodeAsUnhealthy(node_id);
});
} | javascript | function healthcheck(node) {
var ended = false;
var node_id = node.host + ':' + node.port;
var client = net.connect(
{port: node.adminport, host: node.host},
function onConnect() {
if (!ended) {
client.write('health\r\n');
}
}
);
client.setTimeout(healthCheckInterval, function() {
client.end();
markNodeAsUnhealthy(node_id);
client.removeAllListeners('data');
ended = true;
});
client.on('data', function(data) {
if (ended) {
return;
}
var health_status = data.toString();
client.end();
ended = true;
if (health_status.indexOf('up') < 0) {
markNodeAsUnhealthy(node_id);
} else {
markNodeAsHealthy(node_id);
}
});
client.on('error', function(e) {
if (ended) {
return;
}
if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
}
markNodeAsUnhealthy(node_id);
});
} | [
"function",
"healthcheck",
"(",
"node",
")",
"{",
"var",
"ended",
"=",
"false",
";",
"var",
"node_id",
"=",
"node",
".",
"host",
"+",
"':'",
"+",
"node",
".",
"port",
";",
"var",
"client",
"=",
"net",
".",
"connect",
"(",
"{",
"port",
":",
"node",
".",
"adminport",
",",
"host",
":",
"node",
".",
"host",
"}",
",",
"function",
"onConnect",
"(",
")",
"{",
"if",
"(",
"!",
"ended",
")",
"{",
"client",
".",
"write",
"(",
"'health\\r\\n'",
")",
";",
"}",
"}",
")",
";",
"client",
".",
"setTimeout",
"(",
"healthCheckInterval",
",",
"function",
"(",
")",
"{",
"client",
".",
"end",
"(",
")",
";",
"markNodeAsUnhealthy",
"(",
"node_id",
")",
";",
"client",
".",
"removeAllListeners",
"(",
"'data'",
")",
";",
"ended",
"=",
"true",
";",
"}",
")",
";",
"client",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"if",
"(",
"ended",
")",
"{",
"return",
";",
"}",
"var",
"health_status",
"=",
"data",
".",
"toString",
"(",
")",
";",
"client",
".",
"end",
"(",
")",
";",
"ended",
"=",
"true",
";",
"if",
"(",
"health_status",
".",
"indexOf",
"(",
"'up'",
")",
"<",
"0",
")",
"{",
"markNodeAsUnhealthy",
"(",
"node_id",
")",
";",
"}",
"else",
"{",
"markNodeAsHealthy",
"(",
"node_id",
")",
";",
"}",
"}",
")",
";",
"client",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"ended",
")",
"{",
"return",
";",
"}",
"if",
"(",
"e",
".",
"code",
"!==",
"'ECONNREFUSED'",
"&&",
"e",
".",
"code",
"!==",
"'EHOSTUNREACH'",
"&&",
"e",
".",
"code",
"!==",
"'ECONNRESET'",
")",
"{",
"log",
"(",
"'Error during healthcheck on node '",
"+",
"node_id",
"+",
"' with '",
"+",
"e",
".",
"code",
",",
"'ERROR'",
")",
";",
"}",
"markNodeAsUnhealthy",
"(",
"node_id",
")",
";",
"}",
")",
";",
"}"
] | Perform health check on node | [
"Perform",
"health",
"check",
"on",
"node"
] | ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9 | https://github.com/statsd/statsd/blob/ef8e4d76d76c3a0cf771e3724cf79ea22f3c50d9/proxy.js#L255-L301 |
3,678 | SAP/openui5 | src/sap.ui.documentation/src/sap/ui/documentation/sdk/model/formatter.js | function (sLink) {
if (sLink[0] === "#") {
sLink = document.location.href.substring(0,document.location.href.search("demoapps\.html")) + sLink;
}
return sLink;
} | javascript | function (sLink) {
if (sLink[0] === "#") {
sLink = document.location.href.substring(0,document.location.href.search("demoapps\.html")) + sLink;
}
return sLink;
} | [
"function",
"(",
"sLink",
")",
"{",
"if",
"(",
"sLink",
"[",
"0",
"]",
"===",
"\"#\"",
")",
"{",
"sLink",
"=",
"document",
".",
"location",
".",
"href",
".",
"substring",
"(",
"0",
",",
"document",
".",
"location",
".",
"href",
".",
"search",
"(",
"\"demoapps\\.html\"",
")",
")",
"+",
"sLink",
";",
"}",
"return",
"sLink",
";",
"}"
] | Formats a library namespace to link to the API reference if it starts with sap.
@public
@param {string} sNamespace value to be formatted
@returns {string} formatted link | [
"Formats",
"a",
"library",
"namespace",
"to",
"link",
"to",
"the",
"API",
"reference",
"if",
"it",
"starts",
"with",
"sap",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/model/formatter.js#L16-L21 |
|
3,679 | SAP/openui5 | src/sap.uxap/src/sap/uxap/ThrottledTaskHelper.js | function(oOldOptions, oNewOptions) {
var oMergedOptions = jQuery.extend({}, oOldOptions, oNewOptions);
jQuery.each(oMergedOptions, function(key) {
oMergedOptions[key] = oOldOptions[key] || oNewOptions[key]; // default merge strategy is inclusive OR
});
return oMergedOptions;
} | javascript | function(oOldOptions, oNewOptions) {
var oMergedOptions = jQuery.extend({}, oOldOptions, oNewOptions);
jQuery.each(oMergedOptions, function(key) {
oMergedOptions[key] = oOldOptions[key] || oNewOptions[key]; // default merge strategy is inclusive OR
});
return oMergedOptions;
} | [
"function",
"(",
"oOldOptions",
",",
"oNewOptions",
")",
"{",
"var",
"oMergedOptions",
"=",
"jQuery",
".",
"extend",
"(",
"{",
"}",
",",
"oOldOptions",
",",
"oNewOptions",
")",
";",
"jQuery",
".",
"each",
"(",
"oMergedOptions",
",",
"function",
"(",
"key",
")",
"{",
"oMergedOptions",
"[",
"key",
"]",
"=",
"oOldOptions",
"[",
"key",
"]",
"||",
"oNewOptions",
"[",
"key",
"]",
";",
"// default merge strategy is inclusive OR",
"}",
")",
";",
"return",
"oMergedOptions",
";",
"}"
] | Updates the task arguments
Default merge strategy is inclusive OR
@private | [
"Updates",
"the",
"task",
"arguments",
"Default",
"merge",
"strategy",
"is",
"inclusive",
"OR"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.uxap/src/sap/uxap/ThrottledTaskHelper.js#L95-L103 |
|
3,680 | SAP/openui5 | src/sap.ui.dt/src/sap/ui/dt/ElementOverlay.js | function(oChild1, oChild2) {
var oGeometry1 = DOMUtil.getGeometry(oChild1);
var oGeometry2 = DOMUtil.getGeometry(oChild2);
var oPosition1 = oGeometry1 && oGeometry1.position;
var oPosition2 = oGeometry2 && oGeometry2.position;
if (oPosition1 && oPosition2) {
var iBottom1 = oPosition1.top + oGeometry1.size.height;
var iBottom2 = oPosition2.top + oGeometry2.size.height;
if (oPosition1.top < oPosition2.top) {
if (iBottom1 >= iBottom2 && oPosition2.left < oPosition1.left) {
/* Example:
+--------------+
+------+ | |
| 2 | | 1 |
+------+ | |
+--------------+
Despites 1st overlay's top is above 2nd element,
the order should be switched, since 2nd element
is shorter and is more to the left
*/
return 1;
} else {
return -1; // do not switch order
}
} else if (oPosition1.top === oPosition2.top) {
if (oPosition1.left === oPosition2.left) {
// Give priority to smaller block by height or width
if (
oGeometry1.size.height < oGeometry2.size.height
|| oGeometry1.size.width < oGeometry2.size.width
) {
return -1;
} else if (
oGeometry1.size.height > oGeometry2.size.height
|| oGeometry1.size.width > oGeometry2.size.width
) {
return 1;
} else {
return 0;
}
} else if (oPosition1.left < oPosition2.left) {
return -1; // order is correct
} else {
return 1; // switch order
}
} else if (iBottom1 <= iBottom2 && oPosition2.left > oPosition1.left) { // if (oPosition1.top > oPosition2.top)
/* see picture above, but switch 1 and 2 - order is correct */
return -1;
} else {
/* Example:
+--------------+
+------+ | 2 |
| 1 | +--------------+
| |
+------+
Since 1st overlay's both top and bottom coordinates are
bellow in dom, then top and bottom of 2nd, they should be switched
*/
return 1;
}
}
return 0;
} | javascript | function(oChild1, oChild2) {
var oGeometry1 = DOMUtil.getGeometry(oChild1);
var oGeometry2 = DOMUtil.getGeometry(oChild2);
var oPosition1 = oGeometry1 && oGeometry1.position;
var oPosition2 = oGeometry2 && oGeometry2.position;
if (oPosition1 && oPosition2) {
var iBottom1 = oPosition1.top + oGeometry1.size.height;
var iBottom2 = oPosition2.top + oGeometry2.size.height;
if (oPosition1.top < oPosition2.top) {
if (iBottom1 >= iBottom2 && oPosition2.left < oPosition1.left) {
/* Example:
+--------------+
+------+ | |
| 2 | | 1 |
+------+ | |
+--------------+
Despites 1st overlay's top is above 2nd element,
the order should be switched, since 2nd element
is shorter and is more to the left
*/
return 1;
} else {
return -1; // do not switch order
}
} else if (oPosition1.top === oPosition2.top) {
if (oPosition1.left === oPosition2.left) {
// Give priority to smaller block by height or width
if (
oGeometry1.size.height < oGeometry2.size.height
|| oGeometry1.size.width < oGeometry2.size.width
) {
return -1;
} else if (
oGeometry1.size.height > oGeometry2.size.height
|| oGeometry1.size.width > oGeometry2.size.width
) {
return 1;
} else {
return 0;
}
} else if (oPosition1.left < oPosition2.left) {
return -1; // order is correct
} else {
return 1; // switch order
}
} else if (iBottom1 <= iBottom2 && oPosition2.left > oPosition1.left) { // if (oPosition1.top > oPosition2.top)
/* see picture above, but switch 1 and 2 - order is correct */
return -1;
} else {
/* Example:
+--------------+
+------+ | 2 |
| 1 | +--------------+
| |
+------+
Since 1st overlay's both top and bottom coordinates are
bellow in dom, then top and bottom of 2nd, they should be switched
*/
return 1;
}
}
return 0;
} | [
"function",
"(",
"oChild1",
",",
"oChild2",
")",
"{",
"var",
"oGeometry1",
"=",
"DOMUtil",
".",
"getGeometry",
"(",
"oChild1",
")",
";",
"var",
"oGeometry2",
"=",
"DOMUtil",
".",
"getGeometry",
"(",
"oChild2",
")",
";",
"var",
"oPosition1",
"=",
"oGeometry1",
"&&",
"oGeometry1",
".",
"position",
";",
"var",
"oPosition2",
"=",
"oGeometry2",
"&&",
"oGeometry2",
".",
"position",
";",
"if",
"(",
"oPosition1",
"&&",
"oPosition2",
")",
"{",
"var",
"iBottom1",
"=",
"oPosition1",
".",
"top",
"+",
"oGeometry1",
".",
"size",
".",
"height",
";",
"var",
"iBottom2",
"=",
"oPosition2",
".",
"top",
"+",
"oGeometry2",
".",
"size",
".",
"height",
";",
"if",
"(",
"oPosition1",
".",
"top",
"<",
"oPosition2",
".",
"top",
")",
"{",
"if",
"(",
"iBottom1",
">=",
"iBottom2",
"&&",
"oPosition2",
".",
"left",
"<",
"oPosition1",
".",
"left",
")",
"{",
"/* Example:\n\t\t\t\t\t\t\t +--------------+\n\t\t\t\t\t\t\t+------+ | |\n\t\t\t\t\t\t\t| 2 | | 1 |\n\t\t\t\t\t\t\t+------+ | |\n\t\t\t\t\t\t\t +--------------+\n\t\t\t\t\t\t\tDespites 1st overlay's top is above 2nd element,\n\t\t\t\t\t\t\tthe order should be switched, since 2nd element\n\t\t\t\t\t\t\tis shorter and is more to the left\n\t\t\t\t\t\t */",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"-",
"1",
";",
"// do not switch order",
"}",
"}",
"else",
"if",
"(",
"oPosition1",
".",
"top",
"===",
"oPosition2",
".",
"top",
")",
"{",
"if",
"(",
"oPosition1",
".",
"left",
"===",
"oPosition2",
".",
"left",
")",
"{",
"// Give priority to smaller block by height or width",
"if",
"(",
"oGeometry1",
".",
"size",
".",
"height",
"<",
"oGeometry2",
".",
"size",
".",
"height",
"||",
"oGeometry1",
".",
"size",
".",
"width",
"<",
"oGeometry2",
".",
"size",
".",
"width",
")",
"{",
"return",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"oGeometry1",
".",
"size",
".",
"height",
">",
"oGeometry2",
".",
"size",
".",
"height",
"||",
"oGeometry1",
".",
"size",
".",
"width",
">",
"oGeometry2",
".",
"size",
".",
"width",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"oPosition1",
".",
"left",
"<",
"oPosition2",
".",
"left",
")",
"{",
"return",
"-",
"1",
";",
"// order is correct",
"}",
"else",
"{",
"return",
"1",
";",
"// switch order",
"}",
"}",
"else",
"if",
"(",
"iBottom1",
"<=",
"iBottom2",
"&&",
"oPosition2",
".",
"left",
">",
"oPosition1",
".",
"left",
")",
"{",
"// if (oPosition1.top > oPosition2.top)",
"/* see picture above, but switch 1 and 2 - order is correct */",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"/* Example:\n\t\t\t\t\t\t +--------------+\n\t\t\t\t\t\t+------+ | 2 |\n\t\t\t\t\t\t| 1 | +--------------+\n\t\t\t\t\t\t| |\n\t\t\t\t\t\t+------+\n\n\t\t\t\t\t\tSince 1st overlay's both top and bottom coordinates are\n\t\t\t\t\t\tbellow in dom, then top and bottom of 2nd, they should be switched\n\t\t\t\t\t */",
"return",
"1",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | compares two DOM Nodes and returns 1, if first child should be bellow in dom order | [
"compares",
"two",
"DOM",
"Nodes",
"and",
"returns",
"1",
"if",
"first",
"child",
"should",
"be",
"bellow",
"in",
"dom",
"order"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.dt/src/sap/ui/dt/ElementOverlay.js#L388-L453 |
|
3,681 | SAP/openui5 | src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js | function() {
var oViewModel = this.getModel("appView"),
bPhoneSize = oViewModel.getProperty("/bPhoneSize");
// Version switch should not be shown on phone sizes or when no versions are found
oViewModel.setProperty("/bShowVersionSwitchInHeader", !bPhoneSize && !!this._aNeoAppVersions);
oViewModel.setProperty("/bShowVersionSwitchInMenu", bPhoneSize && !!this._aNeoAppVersions);
} | javascript | function() {
var oViewModel = this.getModel("appView"),
bPhoneSize = oViewModel.getProperty("/bPhoneSize");
// Version switch should not be shown on phone sizes or when no versions are found
oViewModel.setProperty("/bShowVersionSwitchInHeader", !bPhoneSize && !!this._aNeoAppVersions);
oViewModel.setProperty("/bShowVersionSwitchInMenu", bPhoneSize && !!this._aNeoAppVersions);
} | [
"function",
"(",
")",
"{",
"var",
"oViewModel",
"=",
"this",
".",
"getModel",
"(",
"\"appView\"",
")",
",",
"bPhoneSize",
"=",
"oViewModel",
".",
"getProperty",
"(",
"\"/bPhoneSize\"",
")",
";",
"// Version switch should not be shown on phone sizes or when no versions are found",
"oViewModel",
".",
"setProperty",
"(",
"\"/bShowVersionSwitchInHeader\"",
",",
"!",
"bPhoneSize",
"&&",
"!",
"!",
"this",
".",
"_aNeoAppVersions",
")",
";",
"oViewModel",
".",
"setProperty",
"(",
"\"/bShowVersionSwitchInMenu\"",
",",
"bPhoneSize",
"&&",
"!",
"!",
"this",
".",
"_aNeoAppVersions",
")",
";",
"}"
] | Determines whether or not to show the version change button.
@private | [
"Determines",
"whether",
"or",
"not",
"to",
"show",
"the",
"version",
"change",
"button",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L414-L421 |
|
3,682 | SAP/openui5 | src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js | function () {
var that = this;
if (!this._oFeedbackDialog) {
this._oFeedbackDialog = new sap.ui.xmlfragment("feedbackDialogFragment", "sap.ui.documentation.sdk.view.FeedbackDialog", this);
this._oView.addDependent(this._oFeedbackDialog);
this._oFeedbackDialog.textInput = Fragment.byId("feedbackDialogFragment", "feedbackInput");
this._oFeedbackDialog.contextCheckBox = Fragment.byId("feedbackDialogFragment", "pageContext");
this._oFeedbackDialog.contextData = Fragment.byId("feedbackDialogFragment", "contextData");
this._oFeedbackDialog.ratingStatus = Fragment.byId("feedbackDialogFragment", "ratingStatus");
this._oFeedbackDialog.ratingStatus.value = 0;
this._oFeedbackDialog.sendButton = Fragment.byId("feedbackDialogFragment", "sendButton");
this._oFeedbackDialog.ratingBar = [
{
button : Fragment.byId("feedbackDialogFragment", "excellent"),
status : "Excellent"
},
{
button : Fragment.byId("feedbackDialogFragment", "good"),
status : "Good"
},
{
button : Fragment.byId("feedbackDialogFragment", "average"),
status : "Average"
},
{
button : Fragment.byId("feedbackDialogFragment", "poor"),
status : "Poor"
},
{
button : Fragment.byId("feedbackDialogFragment", "veryPoor"),
status : "Very Poor"
}
];
this._oFeedbackDialog.reset = function () {
this.sendButton.setEnabled(false);
this.textInput.setValue("");
this.contextCheckBox.setSelected(true);
this.ratingStatus.setText("");
this.ratingStatus.setState("None");
this.ratingStatus.value = 0;
this.contextData.setVisible(false);
this.ratingBar.forEach(function(oRatingBarElement){
if (oRatingBarElement.button.getPressed()) {
oRatingBarElement.button.setPressed(false);
}
});
};
this._oFeedbackDialog.updateContextData = function() {
var sVersion = that._getUI5Version(),
sUI5Distribution = that._getUI5Distribution();
if (this.contextCheckBox.getSelected()) {
this.contextData.setValue("Location: " + that._getCurrentPageRelativeURL() + "\n" + sUI5Distribution + " Version: " + sVersion);
} else {
this.contextData.setValue(sUI5Distribution + " Version: " + sVersion);
}
};
this._oFeedbackDialog.updateContextData();
}
this._oFeedbackDialog.updateContextData();
if (!this._oFeedbackDialog.isOpen()) {
syncStyleClass("sapUiSizeCompact", this.getView(), this._oFeedbackDialog);
this._oFeedbackDialog.open();
}
} | javascript | function () {
var that = this;
if (!this._oFeedbackDialog) {
this._oFeedbackDialog = new sap.ui.xmlfragment("feedbackDialogFragment", "sap.ui.documentation.sdk.view.FeedbackDialog", this);
this._oView.addDependent(this._oFeedbackDialog);
this._oFeedbackDialog.textInput = Fragment.byId("feedbackDialogFragment", "feedbackInput");
this._oFeedbackDialog.contextCheckBox = Fragment.byId("feedbackDialogFragment", "pageContext");
this._oFeedbackDialog.contextData = Fragment.byId("feedbackDialogFragment", "contextData");
this._oFeedbackDialog.ratingStatus = Fragment.byId("feedbackDialogFragment", "ratingStatus");
this._oFeedbackDialog.ratingStatus.value = 0;
this._oFeedbackDialog.sendButton = Fragment.byId("feedbackDialogFragment", "sendButton");
this._oFeedbackDialog.ratingBar = [
{
button : Fragment.byId("feedbackDialogFragment", "excellent"),
status : "Excellent"
},
{
button : Fragment.byId("feedbackDialogFragment", "good"),
status : "Good"
},
{
button : Fragment.byId("feedbackDialogFragment", "average"),
status : "Average"
},
{
button : Fragment.byId("feedbackDialogFragment", "poor"),
status : "Poor"
},
{
button : Fragment.byId("feedbackDialogFragment", "veryPoor"),
status : "Very Poor"
}
];
this._oFeedbackDialog.reset = function () {
this.sendButton.setEnabled(false);
this.textInput.setValue("");
this.contextCheckBox.setSelected(true);
this.ratingStatus.setText("");
this.ratingStatus.setState("None");
this.ratingStatus.value = 0;
this.contextData.setVisible(false);
this.ratingBar.forEach(function(oRatingBarElement){
if (oRatingBarElement.button.getPressed()) {
oRatingBarElement.button.setPressed(false);
}
});
};
this._oFeedbackDialog.updateContextData = function() {
var sVersion = that._getUI5Version(),
sUI5Distribution = that._getUI5Distribution();
if (this.contextCheckBox.getSelected()) {
this.contextData.setValue("Location: " + that._getCurrentPageRelativeURL() + "\n" + sUI5Distribution + " Version: " + sVersion);
} else {
this.contextData.setValue(sUI5Distribution + " Version: " + sVersion);
}
};
this._oFeedbackDialog.updateContextData();
}
this._oFeedbackDialog.updateContextData();
if (!this._oFeedbackDialog.isOpen()) {
syncStyleClass("sapUiSizeCompact", this.getView(), this._oFeedbackDialog);
this._oFeedbackDialog.open();
}
} | [
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_oFeedbackDialog",
")",
"{",
"this",
".",
"_oFeedbackDialog",
"=",
"new",
"sap",
".",
"ui",
".",
"xmlfragment",
"(",
"\"feedbackDialogFragment\"",
",",
"\"sap.ui.documentation.sdk.view.FeedbackDialog\"",
",",
"this",
")",
";",
"this",
".",
"_oView",
".",
"addDependent",
"(",
"this",
".",
"_oFeedbackDialog",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"feedbackInput\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"contextCheckBox",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"pageContext\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"contextData",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"contextData\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"ratingStatus\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"=",
"0",
";",
"this",
".",
"_oFeedbackDialog",
".",
"sendButton",
"=",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"sendButton\"",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"ratingBar",
"=",
"[",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"excellent\"",
")",
",",
"status",
":",
"\"Excellent\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"good\"",
")",
",",
"status",
":",
"\"Good\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"average\"",
")",
",",
"status",
":",
"\"Average\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"poor\"",
")",
",",
"status",
":",
"\"Poor\"",
"}",
",",
"{",
"button",
":",
"Fragment",
".",
"byId",
"(",
"\"feedbackDialogFragment\"",
",",
"\"veryPoor\"",
")",
",",
"status",
":",
"\"Very Poor\"",
"}",
"]",
";",
"this",
".",
"_oFeedbackDialog",
".",
"reset",
"=",
"function",
"(",
")",
"{",
"this",
".",
"sendButton",
".",
"setEnabled",
"(",
"false",
")",
";",
"this",
".",
"textInput",
".",
"setValue",
"(",
"\"\"",
")",
";",
"this",
".",
"contextCheckBox",
".",
"setSelected",
"(",
"true",
")",
";",
"this",
".",
"ratingStatus",
".",
"setText",
"(",
"\"\"",
")",
";",
"this",
".",
"ratingStatus",
".",
"setState",
"(",
"\"None\"",
")",
";",
"this",
".",
"ratingStatus",
".",
"value",
"=",
"0",
";",
"this",
".",
"contextData",
".",
"setVisible",
"(",
"false",
")",
";",
"this",
".",
"ratingBar",
".",
"forEach",
"(",
"function",
"(",
"oRatingBarElement",
")",
"{",
"if",
"(",
"oRatingBarElement",
".",
"button",
".",
"getPressed",
"(",
")",
")",
"{",
"oRatingBarElement",
".",
"button",
".",
"setPressed",
"(",
"false",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"=",
"function",
"(",
")",
"{",
"var",
"sVersion",
"=",
"that",
".",
"_getUI5Version",
"(",
")",
",",
"sUI5Distribution",
"=",
"that",
".",
"_getUI5Distribution",
"(",
")",
";",
"if",
"(",
"this",
".",
"contextCheckBox",
".",
"getSelected",
"(",
")",
")",
"{",
"this",
".",
"contextData",
".",
"setValue",
"(",
"\"Location: \"",
"+",
"that",
".",
"_getCurrentPageRelativeURL",
"(",
")",
"+",
"\"\\n\"",
"+",
"sUI5Distribution",
"+",
"\" Version: \"",
"+",
"sVersion",
")",
";",
"}",
"else",
"{",
"this",
".",
"contextData",
".",
"setValue",
"(",
"sUI5Distribution",
"+",
"\" Version: \"",
"+",
"sVersion",
")",
";",
"}",
"}",
";",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"(",
")",
";",
"}",
"this",
".",
"_oFeedbackDialog",
".",
"updateContextData",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"_oFeedbackDialog",
".",
"isOpen",
"(",
")",
")",
"{",
"syncStyleClass",
"(",
"\"sapUiSizeCompact\"",
",",
"this",
".",
"getView",
"(",
")",
",",
"this",
".",
"_oFeedbackDialog",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"open",
"(",
")",
";",
"}",
"}"
] | Opens a dialog to give feedback on the demo kit | [
"Opens",
"a",
"dialog",
"to",
"give",
"feedback",
"on",
"the",
"demo",
"kit"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L441-L508 |
|
3,683 | SAP/openui5 | src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js | function() {
var data = {};
if (this._oFeedbackDialog.contextCheckBox.getSelected()) {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"page": this._getCurrentPageRelativeURL(), "attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
} else {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
}
// send feedback
this._oFeedbackDialog.setBusyIndicatorDelay(0);
this._oFeedbackDialog.setBusy(true);
jQuery.ajax({
url: this.FEEDBACK_SERVICE_URL,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data)
}).
done(
function () {
MessageBox.success("Your feedback has been sent.", {title: "Thank you!"});
this._oFeedbackDialog.reset();
this._oFeedbackDialog.close();
this._oFeedbackDialog.setBusy(false);
}.bind(this)
).
fail(
function (oRequest, sStatus, sError) {
var sErrorDetails = sError; // + "\n" + oRequest.responseText;
MessageBox.error("An error occurred sending your feedback:\n" + sErrorDetails, {title: "Sorry!"});
this._oFeedbackDialog.setBusy(false);
}.bind(this)
);
} | javascript | function() {
var data = {};
if (this._oFeedbackDialog.contextCheckBox.getSelected()) {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"page": this._getCurrentPageRelativeURL(), "attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
} else {
data = {
"texts": {
"t1": this._oFeedbackDialog.textInput.getValue()
},
"ratings":{
"r1": {"value" : this._oFeedbackDialog.ratingStatus.value}
},
"context": {"attr1": this._getUI5Distribution() + ":" + sap.ui.version}
};
}
// send feedback
this._oFeedbackDialog.setBusyIndicatorDelay(0);
this._oFeedbackDialog.setBusy(true);
jQuery.ajax({
url: this.FEEDBACK_SERVICE_URL,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data)
}).
done(
function () {
MessageBox.success("Your feedback has been sent.", {title: "Thank you!"});
this._oFeedbackDialog.reset();
this._oFeedbackDialog.close();
this._oFeedbackDialog.setBusy(false);
}.bind(this)
).
fail(
function (oRequest, sStatus, sError) {
var sErrorDetails = sError; // + "\n" + oRequest.responseText;
MessageBox.error("An error occurred sending your feedback:\n" + sErrorDetails, {title: "Sorry!"});
this._oFeedbackDialog.setBusy(false);
}.bind(this)
);
} | [
"function",
"(",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"if",
"(",
"this",
".",
"_oFeedbackDialog",
".",
"contextCheckBox",
".",
"getSelected",
"(",
")",
")",
"{",
"data",
"=",
"{",
"\"texts\"",
":",
"{",
"\"t1\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
".",
"getValue",
"(",
")",
"}",
",",
"\"ratings\"",
":",
"{",
"\"r1\"",
":",
"{",
"\"value\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"}",
"}",
",",
"\"context\"",
":",
"{",
"\"page\"",
":",
"this",
".",
"_getCurrentPageRelativeURL",
"(",
")",
",",
"\"attr1\"",
":",
"this",
".",
"_getUI5Distribution",
"(",
")",
"+",
"\":\"",
"+",
"sap",
".",
"ui",
".",
"version",
"}",
"}",
";",
"}",
"else",
"{",
"data",
"=",
"{",
"\"texts\"",
":",
"{",
"\"t1\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"textInput",
".",
"getValue",
"(",
")",
"}",
",",
"\"ratings\"",
":",
"{",
"\"r1\"",
":",
"{",
"\"value\"",
":",
"this",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"}",
"}",
",",
"\"context\"",
":",
"{",
"\"attr1\"",
":",
"this",
".",
"_getUI5Distribution",
"(",
")",
"+",
"\":\"",
"+",
"sap",
".",
"ui",
".",
"version",
"}",
"}",
";",
"}",
"// send feedback",
"this",
".",
"_oFeedbackDialog",
".",
"setBusyIndicatorDelay",
"(",
"0",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"true",
")",
";",
"jQuery",
".",
"ajax",
"(",
"{",
"url",
":",
"this",
".",
"FEEDBACK_SERVICE_URL",
",",
"type",
":",
"\"POST\"",
",",
"contentType",
":",
"\"application/json\"",
",",
"data",
":",
"JSON",
".",
"stringify",
"(",
"data",
")",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"MessageBox",
".",
"success",
"(",
"\"Your feedback has been sent.\"",
",",
"{",
"title",
":",
"\"Thank you!\"",
"}",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"reset",
"(",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"close",
"(",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"false",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"fail",
"(",
"function",
"(",
"oRequest",
",",
"sStatus",
",",
"sError",
")",
"{",
"var",
"sErrorDetails",
"=",
"sError",
";",
"// + \"\\n\" + oRequest.responseText;",
"MessageBox",
".",
"error",
"(",
"\"An error occurred sending your feedback:\\n\"",
"+",
"sErrorDetails",
",",
"{",
"title",
":",
"\"Sorry!\"",
"}",
")",
";",
"this",
".",
"_oFeedbackDialog",
".",
"setBusy",
"(",
"false",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Event handler for the send feedback button | [
"Event",
"handler",
"for",
"the",
"send",
"feedback",
"button"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L513-L564 |
|
3,684 | SAP/openui5 | src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js | function(oEvent) {
var that = this;
var oPressedButton = oEvent.getSource();
that._oFeedbackDialog.ratingBar.forEach(function(oRatingBarElement) {
if (oPressedButton !== oRatingBarElement.button) {
oRatingBarElement.button.setPressed(false);
} else {
if (!oRatingBarElement.button.getPressed()) {
setRatingStatus("None", "", 0);
} else {
switch (oRatingBarElement.status) {
case "Excellent":
setRatingStatus("Success", oRatingBarElement.status, 5);
break;
case "Good":
setRatingStatus("Success", oRatingBarElement.status, 4);
break;
case "Average":
setRatingStatus("None", oRatingBarElement.status, 3);
break;
case "Poor":
setRatingStatus("Warning", oRatingBarElement.status, 2);
break;
case "Very Poor":
setRatingStatus("Error", oRatingBarElement.status, 1);
}
}
}
});
function setRatingStatus(sState, sText, iValue) {
that._oFeedbackDialog.ratingStatus.setState(sState);
that._oFeedbackDialog.ratingStatus.setText(sText);
that._oFeedbackDialog.ratingStatus.value = iValue;
if (iValue) {
that._oFeedbackDialog.sendButton.setEnabled(true);
} else {
that._oFeedbackDialog.sendButton.setEnabled(false);
}
}
} | javascript | function(oEvent) {
var that = this;
var oPressedButton = oEvent.getSource();
that._oFeedbackDialog.ratingBar.forEach(function(oRatingBarElement) {
if (oPressedButton !== oRatingBarElement.button) {
oRatingBarElement.button.setPressed(false);
} else {
if (!oRatingBarElement.button.getPressed()) {
setRatingStatus("None", "", 0);
} else {
switch (oRatingBarElement.status) {
case "Excellent":
setRatingStatus("Success", oRatingBarElement.status, 5);
break;
case "Good":
setRatingStatus("Success", oRatingBarElement.status, 4);
break;
case "Average":
setRatingStatus("None", oRatingBarElement.status, 3);
break;
case "Poor":
setRatingStatus("Warning", oRatingBarElement.status, 2);
break;
case "Very Poor":
setRatingStatus("Error", oRatingBarElement.status, 1);
}
}
}
});
function setRatingStatus(sState, sText, iValue) {
that._oFeedbackDialog.ratingStatus.setState(sState);
that._oFeedbackDialog.ratingStatus.setText(sText);
that._oFeedbackDialog.ratingStatus.value = iValue;
if (iValue) {
that._oFeedbackDialog.sendButton.setEnabled(true);
} else {
that._oFeedbackDialog.sendButton.setEnabled(false);
}
}
} | [
"function",
"(",
"oEvent",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"oPressedButton",
"=",
"oEvent",
".",
"getSource",
"(",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingBar",
".",
"forEach",
"(",
"function",
"(",
"oRatingBarElement",
")",
"{",
"if",
"(",
"oPressedButton",
"!==",
"oRatingBarElement",
".",
"button",
")",
"{",
"oRatingBarElement",
".",
"button",
".",
"setPressed",
"(",
"false",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"oRatingBarElement",
".",
"button",
".",
"getPressed",
"(",
")",
")",
"{",
"setRatingStatus",
"(",
"\"None\"",
",",
"\"\"",
",",
"0",
")",
";",
"}",
"else",
"{",
"switch",
"(",
"oRatingBarElement",
".",
"status",
")",
"{",
"case",
"\"Excellent\"",
":",
"setRatingStatus",
"(",
"\"Success\"",
",",
"oRatingBarElement",
".",
"status",
",",
"5",
")",
";",
"break",
";",
"case",
"\"Good\"",
":",
"setRatingStatus",
"(",
"\"Success\"",
",",
"oRatingBarElement",
".",
"status",
",",
"4",
")",
";",
"break",
";",
"case",
"\"Average\"",
":",
"setRatingStatus",
"(",
"\"None\"",
",",
"oRatingBarElement",
".",
"status",
",",
"3",
")",
";",
"break",
";",
"case",
"\"Poor\"",
":",
"setRatingStatus",
"(",
"\"Warning\"",
",",
"oRatingBarElement",
".",
"status",
",",
"2",
")",
";",
"break",
";",
"case",
"\"Very Poor\"",
":",
"setRatingStatus",
"(",
"\"Error\"",
",",
"oRatingBarElement",
".",
"status",
",",
"1",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"function",
"setRatingStatus",
"(",
"sState",
",",
"sText",
",",
"iValue",
")",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"setState",
"(",
"sState",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"setText",
"(",
"sText",
")",
";",
"that",
".",
"_oFeedbackDialog",
".",
"ratingStatus",
".",
"value",
"=",
"iValue",
";",
"if",
"(",
"iValue",
")",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"sendButton",
".",
"setEnabled",
"(",
"true",
")",
";",
"}",
"else",
"{",
"that",
".",
"_oFeedbackDialog",
".",
"sendButton",
".",
"setEnabled",
"(",
"false",
")",
";",
"}",
"}",
"}"
] | Event handler for the rating to update the label and the data
@param {sap.ui.base.Event} | [
"Event",
"handler",
"for",
"the",
"rating",
"to",
"update",
"the",
"label",
"and",
"the",
"data"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.documentation/src/sap/ui/documentation/sdk/controller/App.controller.js#L592-L633 |
|
3,685 | SAP/openui5 | src/sap.ui.core/src/sap/ui/thirdparty/hasher.js | function(path){
// ##### BEGIN: MODIFIED BY SAP
var dispatchFunction;
// ##### END: MODIFIED BY SAP
path = _makePath.apply(null, arguments);
if(path !== _hash){
// we should store raw value
// ##### BEGIN: MODIFIED BY SAP
dispatchFunction = _registerChange(path);
if (!hasher.raw) {
path = _encodePath(path);
}
window.location.hash = '#' + path;
dispatchFunction && dispatchFunction();
// ##### END: MODIFIED BY SAP
}
} | javascript | function(path){
// ##### BEGIN: MODIFIED BY SAP
var dispatchFunction;
// ##### END: MODIFIED BY SAP
path = _makePath.apply(null, arguments);
if(path !== _hash){
// we should store raw value
// ##### BEGIN: MODIFIED BY SAP
dispatchFunction = _registerChange(path);
if (!hasher.raw) {
path = _encodePath(path);
}
window.location.hash = '#' + path;
dispatchFunction && dispatchFunction();
// ##### END: MODIFIED BY SAP
}
} | [
"function",
"(",
"path",
")",
"{",
"// ##### BEGIN: MODIFIED BY SAP",
"var",
"dispatchFunction",
";",
"// ##### END: MODIFIED BY SAP",
"path",
"=",
"_makePath",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
";",
"if",
"(",
"path",
"!==",
"_hash",
")",
"{",
"// we should store raw value",
"// ##### BEGIN: MODIFIED BY SAP",
"dispatchFunction",
"=",
"_registerChange",
"(",
"path",
")",
";",
"if",
"(",
"!",
"hasher",
".",
"raw",
")",
"{",
"path",
"=",
"_encodePath",
"(",
"path",
")",
";",
"}",
"window",
".",
"location",
".",
"hash",
"=",
"'#'",
"+",
"path",
";",
"dispatchFunction",
"&&",
"dispatchFunction",
"(",
")",
";",
"// ##### END: MODIFIED BY SAP",
"}",
"}"
] | Set Hash value, generating a new history record.
@param {...string} path Hash value without '#'. Hasher will join
path segments using `hasher.separator` and prepend/append hash value
with `hasher.appendHash` and `hasher.prependHash`
@example hasher.setHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor' | [
"Set",
"Hash",
"value",
"generating",
"a",
"new",
"history",
"record",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/hasher.js#L361-L378 |
|
3,686 | SAP/openui5 | src/sap.ui.demokit/src/sap/ui/demokit/util/jsanalyzer/Doclet.js | Doclet | function Doclet(comment) {
this.comment = comment = unwrap(comment);
this.tags = [];
var m;
var lastContent = 0;
var lastTag = "description";
while ((m = rtag.exec(comment)) != null) {
this._addTag(lastTag, comment.slice(lastContent, m.index));
lastTag = m[2];
lastContent = rtag.lastIndex;
}
this._addTag(lastTag, comment.slice(lastContent));
} | javascript | function Doclet(comment) {
this.comment = comment = unwrap(comment);
this.tags = [];
var m;
var lastContent = 0;
var lastTag = "description";
while ((m = rtag.exec(comment)) != null) {
this._addTag(lastTag, comment.slice(lastContent, m.index));
lastTag = m[2];
lastContent = rtag.lastIndex;
}
this._addTag(lastTag, comment.slice(lastContent));
} | [
"function",
"Doclet",
"(",
"comment",
")",
"{",
"this",
".",
"comment",
"=",
"comment",
"=",
"unwrap",
"(",
"comment",
")",
";",
"this",
".",
"tags",
"=",
"[",
"]",
";",
"var",
"m",
";",
"var",
"lastContent",
"=",
"0",
";",
"var",
"lastTag",
"=",
"\"description\"",
";",
"while",
"(",
"(",
"m",
"=",
"rtag",
".",
"exec",
"(",
"comment",
")",
")",
"!=",
"null",
")",
"{",
"this",
".",
"_addTag",
"(",
"lastTag",
",",
"comment",
".",
"slice",
"(",
"lastContent",
",",
"m",
".",
"index",
")",
")",
";",
"lastTag",
"=",
"m",
"[",
"2",
"]",
";",
"lastContent",
"=",
"rtag",
".",
"lastIndex",
";",
"}",
"this",
".",
"_addTag",
"(",
"lastTag",
",",
"comment",
".",
"slice",
"(",
"lastContent",
")",
")",
";",
"}"
] | Creates a Doclet from the given comment string
@param {string} comment Comment string.
@constructor
@private | [
"Creates",
"a",
"Doclet",
"from",
"the",
"given",
"comment",
"string"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.demokit/src/sap/ui/demokit/util/jsanalyzer/Doclet.js#L42-L56 |
3,687 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/Control.js | fnAppendBusyIndicator | function fnAppendBusyIndicator() {
// Only append if busy state is still set
if (!this.getBusy()) {
return;
}
var $this = this.$(this._sBusySection);
//If there is a pending delayed call to append the busy indicator, we can clear it now
if (this._busyIndicatorDelayedCallId) {
clearTimeout(this._busyIndicatorDelayedCallId);
delete this._busyIndicatorDelayedCallId;
}
// if no busy section/control jquery instance could be retrieved -> the control is not part of the dom anymore
// this might happen in certain scenarios when e.g. a dialog is closed faster than the busyIndicatorDelay
if (!$this || $this.length === 0) {
Log.warning("BusyIndicator could not be rendered. The outer control instance is not valid anymore.");
return;
}
if (this._sBlockSection === this._sBusySection) {
if (this._oBlockState) {
BusyIndicatorUtils.addHTML(this._oBlockState, this.getBusyIndicatorSize());
BlockLayerUtils.toggleAnimationStyle(this._oBlockState, true);
this._oBusyBlockState = this._oBlockState;
} else {
// BusyIndicator is the first blocking element created (and )
fnAddStandaloneBusyIndicator.call(this);
}
} else {
// Standalone busy indicator
fnAddStandaloneBusyIndicator.call(this);
}
} | javascript | function fnAppendBusyIndicator() {
// Only append if busy state is still set
if (!this.getBusy()) {
return;
}
var $this = this.$(this._sBusySection);
//If there is a pending delayed call to append the busy indicator, we can clear it now
if (this._busyIndicatorDelayedCallId) {
clearTimeout(this._busyIndicatorDelayedCallId);
delete this._busyIndicatorDelayedCallId;
}
// if no busy section/control jquery instance could be retrieved -> the control is not part of the dom anymore
// this might happen in certain scenarios when e.g. a dialog is closed faster than the busyIndicatorDelay
if (!$this || $this.length === 0) {
Log.warning("BusyIndicator could not be rendered. The outer control instance is not valid anymore.");
return;
}
if (this._sBlockSection === this._sBusySection) {
if (this._oBlockState) {
BusyIndicatorUtils.addHTML(this._oBlockState, this.getBusyIndicatorSize());
BlockLayerUtils.toggleAnimationStyle(this._oBlockState, true);
this._oBusyBlockState = this._oBlockState;
} else {
// BusyIndicator is the first blocking element created (and )
fnAddStandaloneBusyIndicator.call(this);
}
} else {
// Standalone busy indicator
fnAddStandaloneBusyIndicator.call(this);
}
} | [
"function",
"fnAppendBusyIndicator",
"(",
")",
"{",
"// Only append if busy state is still set",
"if",
"(",
"!",
"this",
".",
"getBusy",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"$this",
"=",
"this",
".",
"$",
"(",
"this",
".",
"_sBusySection",
")",
";",
"//If there is a pending delayed call to append the busy indicator, we can clear it now",
"if",
"(",
"this",
".",
"_busyIndicatorDelayedCallId",
")",
"{",
"clearTimeout",
"(",
"this",
".",
"_busyIndicatorDelayedCallId",
")",
";",
"delete",
"this",
".",
"_busyIndicatorDelayedCallId",
";",
"}",
"// if no busy section/control jquery instance could be retrieved -> the control is not part of the dom anymore",
"// this might happen in certain scenarios when e.g. a dialog is closed faster than the busyIndicatorDelay",
"if",
"(",
"!",
"$this",
"||",
"$this",
".",
"length",
"===",
"0",
")",
"{",
"Log",
".",
"warning",
"(",
"\"BusyIndicator could not be rendered. The outer control instance is not valid anymore.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_sBlockSection",
"===",
"this",
".",
"_sBusySection",
")",
"{",
"if",
"(",
"this",
".",
"_oBlockState",
")",
"{",
"BusyIndicatorUtils",
".",
"addHTML",
"(",
"this",
".",
"_oBlockState",
",",
"this",
".",
"getBusyIndicatorSize",
"(",
")",
")",
";",
"BlockLayerUtils",
".",
"toggleAnimationStyle",
"(",
"this",
".",
"_oBlockState",
",",
"true",
")",
";",
"this",
".",
"_oBusyBlockState",
"=",
"this",
".",
"_oBlockState",
";",
"}",
"else",
"{",
"// BusyIndicator is the first blocking element created (and )",
"fnAddStandaloneBusyIndicator",
".",
"call",
"(",
"this",
")",
";",
"}",
"}",
"else",
"{",
"// Standalone busy indicator",
"fnAddStandaloneBusyIndicator",
".",
"call",
"(",
"this",
")",
";",
"}",
"}"
] | Add busy indicator to DOM
@private | [
"Add",
"busy",
"indicator",
"to",
"DOM"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L721-L759 |
3,688 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/Control.js | fnAddStandaloneBlockLayer | function fnAddStandaloneBlockLayer () {
this._oBlockState = BlockLayerUtils.block(this, this.getId() + "-blockedLayer", this._sBlockSection);
jQuery(this._oBlockState.$blockLayer.get(0)).addClass("sapUiBlockLayerOnly");
} | javascript | function fnAddStandaloneBlockLayer () {
this._oBlockState = BlockLayerUtils.block(this, this.getId() + "-blockedLayer", this._sBlockSection);
jQuery(this._oBlockState.$blockLayer.get(0)).addClass("sapUiBlockLayerOnly");
} | [
"function",
"fnAddStandaloneBlockLayer",
"(",
")",
"{",
"this",
".",
"_oBlockState",
"=",
"BlockLayerUtils",
".",
"block",
"(",
"this",
",",
"this",
".",
"getId",
"(",
")",
"+",
"\"-blockedLayer\"",
",",
"this",
".",
"_sBlockSection",
")",
";",
"jQuery",
"(",
"this",
".",
"_oBlockState",
".",
"$blockLayer",
".",
"get",
"(",
"0",
")",
")",
".",
"addClass",
"(",
"\"sapUiBlockLayerOnly\"",
")",
";",
"}"
] | Adds a standalone block-layer. Might be shared with a BusyIndicator later on. | [
"Adds",
"a",
"standalone",
"block",
"-",
"layer",
".",
"Might",
"be",
"shared",
"with",
"a",
"BusyIndicator",
"later",
"on",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L764-L767 |
3,689 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/Control.js | fnAddStandaloneBusyIndicator | function fnAddStandaloneBusyIndicator () {
this._oBusyBlockState = BlockLayerUtils.block(this, this.getId() + "-busyIndicator", this._sBusySection);
BusyIndicatorUtils.addHTML(this._oBusyBlockState, this.getBusyIndicatorSize());
} | javascript | function fnAddStandaloneBusyIndicator () {
this._oBusyBlockState = BlockLayerUtils.block(this, this.getId() + "-busyIndicator", this._sBusySection);
BusyIndicatorUtils.addHTML(this._oBusyBlockState, this.getBusyIndicatorSize());
} | [
"function",
"fnAddStandaloneBusyIndicator",
"(",
")",
"{",
"this",
".",
"_oBusyBlockState",
"=",
"BlockLayerUtils",
".",
"block",
"(",
"this",
",",
"this",
".",
"getId",
"(",
")",
"+",
"\"-busyIndicator\"",
",",
"this",
".",
"_sBusySection",
")",
";",
"BusyIndicatorUtils",
".",
"addHTML",
"(",
"this",
".",
"_oBusyBlockState",
",",
"this",
".",
"getBusyIndicatorSize",
"(",
")",
")",
";",
"}"
] | Adds a standalone BusyIndicator.
The block-layer code is able to recognize that a new block-layer is not needed. | [
"Adds",
"a",
"standalone",
"BusyIndicator",
".",
"The",
"block",
"-",
"layer",
"code",
"is",
"able",
"to",
"recognize",
"that",
"a",
"new",
"block",
"-",
"layer",
"is",
"not",
"needed",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L773-L776 |
3,690 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/Control.js | fnRemoveBusyIndicator | function fnRemoveBusyIndicator(bForceRemoval) {
// removing all block layers is done upon rerendering and destroy of the control
if (bForceRemoval) {
fnRemoveAllBlockLayers.call(this);
return;
}
var $this = this.$(this._sBusySection);
$this.removeClass('sapUiLocalBusy');
//Unset the actual DOM Element´s 'aria-busy'
$this.removeAttr('aria-busy');
if (this._sBlockSection === this._sBusySection) {
if (!this.getBlocked() && !this.getBusy()) {
// Remove shared block state & busy block state reference
fnRemoveAllBlockLayers.call(this);
} else if (this.getBlocked()) {
// Hide animation in shared block layer
BlockLayerUtils.toggleAnimationStyle(this._oBlockState || this._oBusyBlockState, false);
this._oBlockState = this._oBusyBlockState;
} else if (this._oBusyBlockState) {
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} else if (this._oBusyBlockState) {
// standalone busy block state
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} | javascript | function fnRemoveBusyIndicator(bForceRemoval) {
// removing all block layers is done upon rerendering and destroy of the control
if (bForceRemoval) {
fnRemoveAllBlockLayers.call(this);
return;
}
var $this = this.$(this._sBusySection);
$this.removeClass('sapUiLocalBusy');
//Unset the actual DOM Element´s 'aria-busy'
$this.removeAttr('aria-busy');
if (this._sBlockSection === this._sBusySection) {
if (!this.getBlocked() && !this.getBusy()) {
// Remove shared block state & busy block state reference
fnRemoveAllBlockLayers.call(this);
} else if (this.getBlocked()) {
// Hide animation in shared block layer
BlockLayerUtils.toggleAnimationStyle(this._oBlockState || this._oBusyBlockState, false);
this._oBlockState = this._oBusyBlockState;
} else if (this._oBusyBlockState) {
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} else if (this._oBusyBlockState) {
// standalone busy block state
BlockLayerUtils.unblock(this._oBusyBlockState);
delete this._oBusyBlockState;
}
} | [
"function",
"fnRemoveBusyIndicator",
"(",
"bForceRemoval",
")",
"{",
"// removing all block layers is done upon rerendering and destroy of the control",
"if",
"(",
"bForceRemoval",
")",
"{",
"fnRemoveAllBlockLayers",
".",
"call",
"(",
"this",
")",
";",
"return",
";",
"}",
"var",
"$this",
"=",
"this",
".",
"$",
"(",
"this",
".",
"_sBusySection",
")",
";",
"$this",
".",
"removeClass",
"(",
"'sapUiLocalBusy'",
")",
";",
"//Unset the actual DOM Element´s 'aria-busy'",
"$this",
".",
"removeAttr",
"(",
"'aria-busy'",
")",
";",
"if",
"(",
"this",
".",
"_sBlockSection",
"===",
"this",
".",
"_sBusySection",
")",
"{",
"if",
"(",
"!",
"this",
".",
"getBlocked",
"(",
")",
"&&",
"!",
"this",
".",
"getBusy",
"(",
")",
")",
"{",
"// Remove shared block state & busy block state reference",
"fnRemoveAllBlockLayers",
".",
"call",
"(",
"this",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"getBlocked",
"(",
")",
")",
"{",
"// Hide animation in shared block layer",
"BlockLayerUtils",
".",
"toggleAnimationStyle",
"(",
"this",
".",
"_oBlockState",
"||",
"this",
".",
"_oBusyBlockState",
",",
"false",
")",
";",
"this",
".",
"_oBlockState",
"=",
"this",
".",
"_oBusyBlockState",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_oBusyBlockState",
")",
"{",
"BlockLayerUtils",
".",
"unblock",
"(",
"this",
".",
"_oBusyBlockState",
")",
";",
"delete",
"this",
".",
"_oBusyBlockState",
";",
"}",
"}",
"else",
"if",
"(",
"this",
".",
"_oBusyBlockState",
")",
"{",
"// standalone busy block state",
"BlockLayerUtils",
".",
"unblock",
"(",
"this",
".",
"_oBusyBlockState",
")",
";",
"delete",
"this",
".",
"_oBusyBlockState",
";",
"}",
"}"
] | Remove busy indicator from DOM
@param {boolean} bForceRemoval Forces the removal of all Block layers
@private | [
"Remove",
"busy",
"indicator",
"from",
"DOM"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/Control.js#L796-L831 |
3,691 | SAP/openui5 | src/sap.ui.core/src/sap/ui/model/odata/ODataMessageParser.js | filterDuplicates | function filterDuplicates(/*ref*/ aMessages){
if (aMessages.length > 1) {
for (var iIndex = 1; iIndex < aMessages.length; iIndex++) {
if (aMessages[0].getCode() == aMessages[iIndex].getCode() && aMessages[0].getMessage() == aMessages[iIndex].getMessage()) {
aMessages.shift(); // Remove outer error, since inner error is more detailed
break;
}
}
}
} | javascript | function filterDuplicates(/*ref*/ aMessages){
if (aMessages.length > 1) {
for (var iIndex = 1; iIndex < aMessages.length; iIndex++) {
if (aMessages[0].getCode() == aMessages[iIndex].getCode() && aMessages[0].getMessage() == aMessages[iIndex].getMessage()) {
aMessages.shift(); // Remove outer error, since inner error is more detailed
break;
}
}
}
} | [
"function",
"filterDuplicates",
"(",
"/*ref*/",
"aMessages",
")",
"{",
"if",
"(",
"aMessages",
".",
"length",
">",
"1",
")",
"{",
"for",
"(",
"var",
"iIndex",
"=",
"1",
";",
"iIndex",
"<",
"aMessages",
".",
"length",
";",
"iIndex",
"++",
")",
"{",
"if",
"(",
"aMessages",
"[",
"0",
"]",
".",
"getCode",
"(",
")",
"==",
"aMessages",
"[",
"iIndex",
"]",
".",
"getCode",
"(",
")",
"&&",
"aMessages",
"[",
"0",
"]",
".",
"getMessage",
"(",
")",
"==",
"aMessages",
"[",
"iIndex",
"]",
".",
"getMessage",
"(",
")",
")",
"{",
"aMessages",
".",
"shift",
"(",
")",
";",
"// Remove outer error, since inner error is more detailed",
"break",
";",
"}",
"}",
"}",
"}"
] | The message container returned by the backend could contain duplicate messages in some scenarios.
The outer error could be identical to an inner error. This makes sense when the outer error is only though as error message container
for the inner errors and therefore shouldn't be end up in a seperate UI message.
This function is used to filter out not relevant outer errors.
@example
{
"error": {
"code": "ABC",
"message": {
"value": "Bad things happened."
},
"innererror": {
"errordetails": [
{
"code": "ABC",
"message": "Bad things happened."
},
...
@private | [
"The",
"message",
"container",
"returned",
"by",
"the",
"backend",
"could",
"contain",
"duplicate",
"messages",
"in",
"some",
"scenarios",
".",
"The",
"outer",
"error",
"could",
"be",
"identical",
"to",
"an",
"inner",
"error",
".",
"This",
"makes",
"sense",
"when",
"the",
"outer",
"error",
"is",
"only",
"though",
"as",
"error",
"message",
"container",
"for",
"the",
"inner",
"errors",
"and",
"therefore",
"shouldn",
"t",
"be",
"end",
"up",
"in",
"a",
"seperate",
"UI",
"message",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/model/odata/ODataMessageParser.js#L892-L901 |
3,692 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/date/Buddhist.js | toBuddhist | function toBuddhist(oGregorian) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oGregorian.year - iEraStartYear + 1;
// Before 1941 new year started on 1st of April
if (oGregorian.year < 1941 && oGregorian.month < 3) {
iYear -= 1;
}
if (oGregorian.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oGregorian.month,
day: oGregorian.day
};
} | javascript | function toBuddhist(oGregorian) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oGregorian.year - iEraStartYear + 1;
// Before 1941 new year started on 1st of April
if (oGregorian.year < 1941 && oGregorian.month < 3) {
iYear -= 1;
}
if (oGregorian.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oGregorian.month,
day: oGregorian.day
};
} | [
"function",
"toBuddhist",
"(",
"oGregorian",
")",
"{",
"var",
"iEraStartYear",
"=",
"UniversalDate",
".",
"getEraStartDate",
"(",
"CalendarType",
".",
"Buddhist",
",",
"0",
")",
".",
"year",
",",
"iYear",
"=",
"oGregorian",
".",
"year",
"-",
"iEraStartYear",
"+",
"1",
";",
"// Before 1941 new year started on 1st of April",
"if",
"(",
"oGregorian",
".",
"year",
"<",
"1941",
"&&",
"oGregorian",
".",
"month",
"<",
"3",
")",
"{",
"iYear",
"-=",
"1",
";",
"}",
"if",
"(",
"oGregorian",
".",
"year",
"===",
"null",
")",
"{",
"iYear",
"=",
"undefined",
";",
"}",
"return",
"{",
"year",
":",
"iYear",
",",
"month",
":",
"oGregorian",
".",
"month",
",",
"day",
":",
"oGregorian",
".",
"day",
"}",
";",
"}"
] | Find the matching Buddhist date for the given gregorian date
@param {object} oGregorian
@return {object} | [
"Find",
"the",
"matching",
"Buddhist",
"date",
"for",
"the",
"given",
"gregorian",
"date"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L48-L63 |
3,693 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/date/Buddhist.js | toGregorian | function toGregorian(oBuddhist) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oBuddhist.year + iEraStartYear - 1;
// Before 1941 new year started on 1st of April
if (iYear < 1941 && oBuddhist.month < 3) {
iYear += 1;
}
if (oBuddhist.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oBuddhist.month,
day: oBuddhist.day
};
} | javascript | function toGregorian(oBuddhist) {
var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
iYear = oBuddhist.year + iEraStartYear - 1;
// Before 1941 new year started on 1st of April
if (iYear < 1941 && oBuddhist.month < 3) {
iYear += 1;
}
if (oBuddhist.year === null) {
iYear = undefined;
}
return {
year: iYear,
month: oBuddhist.month,
day: oBuddhist.day
};
} | [
"function",
"toGregorian",
"(",
"oBuddhist",
")",
"{",
"var",
"iEraStartYear",
"=",
"UniversalDate",
".",
"getEraStartDate",
"(",
"CalendarType",
".",
"Buddhist",
",",
"0",
")",
".",
"year",
",",
"iYear",
"=",
"oBuddhist",
".",
"year",
"+",
"iEraStartYear",
"-",
"1",
";",
"// Before 1941 new year started on 1st of April",
"if",
"(",
"iYear",
"<",
"1941",
"&&",
"oBuddhist",
".",
"month",
"<",
"3",
")",
"{",
"iYear",
"+=",
"1",
";",
"}",
"if",
"(",
"oBuddhist",
".",
"year",
"===",
"null",
")",
"{",
"iYear",
"=",
"undefined",
";",
"}",
"return",
"{",
"year",
":",
"iYear",
",",
"month",
":",
"oBuddhist",
".",
"month",
",",
"day",
":",
"oBuddhist",
".",
"day",
"}",
";",
"}"
] | Calculate gregorian year from Buddhist year and month
@param {object} oBuddhist
@return {int} | [
"Calculate",
"gregorian",
"year",
"from",
"Buddhist",
"year",
"and",
"month"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L71-L86 |
3,694 | SAP/openui5 | src/sap.ui.core/src/sap/ui/core/date/Buddhist.js | toGregorianArguments | function toGregorianArguments(aArgs) {
var oBuddhist, oGregorian;
oBuddhist = {
year: aArgs[0],
month: aArgs[1],
day: aArgs[2] !== undefined ? aArgs[2] : 1
};
oGregorian = toGregorian(oBuddhist);
aArgs[0] = oGregorian.year;
return aArgs;
} | javascript | function toGregorianArguments(aArgs) {
var oBuddhist, oGregorian;
oBuddhist = {
year: aArgs[0],
month: aArgs[1],
day: aArgs[2] !== undefined ? aArgs[2] : 1
};
oGregorian = toGregorian(oBuddhist);
aArgs[0] = oGregorian.year;
return aArgs;
} | [
"function",
"toGregorianArguments",
"(",
"aArgs",
")",
"{",
"var",
"oBuddhist",
",",
"oGregorian",
";",
"oBuddhist",
"=",
"{",
"year",
":",
"aArgs",
"[",
"0",
"]",
",",
"month",
":",
"aArgs",
"[",
"1",
"]",
",",
"day",
":",
"aArgs",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"aArgs",
"[",
"2",
"]",
":",
"1",
"}",
";",
"oGregorian",
"=",
"toGregorian",
"(",
"oBuddhist",
")",
";",
"aArgs",
"[",
"0",
"]",
"=",
"oGregorian",
".",
"year",
";",
"return",
"aArgs",
";",
"}"
] | Convert arguments array from Buddhist date to gregorian data
@param {object} oBuddhist
@return {int} | [
"Convert",
"arguments",
"array",
"from",
"Buddhist",
"date",
"to",
"gregorian",
"data"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/core/date/Buddhist.js#L94-L104 |
3,695 | SAP/openui5 | src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js | function (oVersionInfo) {
var bResult = false,
sFrameworkInfo = "";
try {
sFrameworkInfo = oVersionInfo.gav ? oVersionInfo.gav : oVersionInfo.name;
bResult = sFrameworkInfo.indexOf('openui5') !== -1 ? true : false;
} catch (e) {
return bResult;
}
return bResult;
} | javascript | function (oVersionInfo) {
var bResult = false,
sFrameworkInfo = "";
try {
sFrameworkInfo = oVersionInfo.gav ? oVersionInfo.gav : oVersionInfo.name;
bResult = sFrameworkInfo.indexOf('openui5') !== -1 ? true : false;
} catch (e) {
return bResult;
}
return bResult;
} | [
"function",
"(",
"oVersionInfo",
")",
"{",
"var",
"bResult",
"=",
"false",
",",
"sFrameworkInfo",
"=",
"\"\"",
";",
"try",
"{",
"sFrameworkInfo",
"=",
"oVersionInfo",
".",
"gav",
"?",
"oVersionInfo",
".",
"gav",
":",
"oVersionInfo",
".",
"name",
";",
"bResult",
"=",
"sFrameworkInfo",
".",
"indexOf",
"(",
"'openui5'",
")",
"!==",
"-",
"1",
"?",
"true",
":",
"false",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"bResult",
";",
"}",
"return",
"bResult",
";",
"}"
] | Checks the distribution of UI5 that the Application is using
@public
@param {object} oVersionInfo information about the UI5 freawork used by the Application
@returns {boolean} result true if the distribution of application is OPENUI5 | [
"Checks",
"the",
"distribution",
"of",
"UI5",
"that",
"the",
"Application",
"is",
"using"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js#L23-L35 |
|
3,696 | SAP/openui5 | src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js | function () {
var that = this;
var oInternalRulesPromise = new Promise(function (resolve) {
if (that.bCanLoadInternalRules !== null) {
resolve(that.bCanLoadInternalRules);
return;
}
jQuery.ajax({
type: "HEAD",
url: sInternalPingFilePath,
success: function () {
that.bCanLoadInternalRules = true;
resolve(that.bCanLoadInternalRules);
},
error: function() {
that.bCanLoadInternalRules = false;
resolve(that.bCanLoadInternalRules);
}
});
});
return oInternalRulesPromise;
} | javascript | function () {
var that = this;
var oInternalRulesPromise = new Promise(function (resolve) {
if (that.bCanLoadInternalRules !== null) {
resolve(that.bCanLoadInternalRules);
return;
}
jQuery.ajax({
type: "HEAD",
url: sInternalPingFilePath,
success: function () {
that.bCanLoadInternalRules = true;
resolve(that.bCanLoadInternalRules);
},
error: function() {
that.bCanLoadInternalRules = false;
resolve(that.bCanLoadInternalRules);
}
});
});
return oInternalRulesPromise;
} | [
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"oInternalRulesPromise",
"=",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"if",
"(",
"that",
".",
"bCanLoadInternalRules",
"!==",
"null",
")",
"{",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"return",
";",
"}",
"jQuery",
".",
"ajax",
"(",
"{",
"type",
":",
"\"HEAD\"",
",",
"url",
":",
"sInternalPingFilePath",
",",
"success",
":",
"function",
"(",
")",
"{",
"that",
".",
"bCanLoadInternalRules",
"=",
"true",
";",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"}",
",",
"error",
":",
"function",
"(",
")",
"{",
"that",
".",
"bCanLoadInternalRules",
"=",
"false",
";",
"resolve",
"(",
"that",
".",
"bCanLoadInternalRules",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"oInternalRulesPromise",
";",
"}"
] | Checks if there are internal rules files that has to be loaded
@returns {Promise} The returned promise resolves with an argument showing
whether internal rules can be loaded or not | [
"Checks",
"if",
"there",
"are",
"internal",
"rules",
"files",
"that",
"has",
"to",
"be",
"loaded"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.support/src/sap/ui/support/supportRules/util/Utils.js#L68-L95 |
|
3,697 | SAP/openui5 | src/sap.ui.layout/src/sap/ui/layout/form/ColumnLayout.js | function(aRows, iField, oLD, oOptions, iLabelSize) {
var iRemain = 0;
var oRow;
for (i = 0; i < aRows.length; i++) {
if (iField >= aRows[i].first && iField <= aRows[i].last) {
oRow = aRows[i];
break;
}
}
if (!oLD) {
oOptions.Size = Math.floor(oRow.availableCells / oRow.defaultFields);
}
if (iField === oRow.first && iField > 0) {
oOptions.Break = true;
if (iLabelSize > 0 && iLabelSize < iColumns && oOptions.Size <= iColumns - iLabelSize) {
oOptions.Space = iLabelSize;
}
}
if (iField === oRow.firstDefault) {
// add remaining cells to first default field
iRemain = oRow.availableCells - oRow.defaultFields * oOptions.Size;
if (iRemain > 0) {
oOptions.Size = oOptions.Size + iRemain;
}
}
} | javascript | function(aRows, iField, oLD, oOptions, iLabelSize) {
var iRemain = 0;
var oRow;
for (i = 0; i < aRows.length; i++) {
if (iField >= aRows[i].first && iField <= aRows[i].last) {
oRow = aRows[i];
break;
}
}
if (!oLD) {
oOptions.Size = Math.floor(oRow.availableCells / oRow.defaultFields);
}
if (iField === oRow.first && iField > 0) {
oOptions.Break = true;
if (iLabelSize > 0 && iLabelSize < iColumns && oOptions.Size <= iColumns - iLabelSize) {
oOptions.Space = iLabelSize;
}
}
if (iField === oRow.firstDefault) {
// add remaining cells to first default field
iRemain = oRow.availableCells - oRow.defaultFields * oOptions.Size;
if (iRemain > 0) {
oOptions.Size = oOptions.Size + iRemain;
}
}
} | [
"function",
"(",
"aRows",
",",
"iField",
",",
"oLD",
",",
"oOptions",
",",
"iLabelSize",
")",
"{",
"var",
"iRemain",
"=",
"0",
";",
"var",
"oRow",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"aRows",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"iField",
">=",
"aRows",
"[",
"i",
"]",
".",
"first",
"&&",
"iField",
"<=",
"aRows",
"[",
"i",
"]",
".",
"last",
")",
"{",
"oRow",
"=",
"aRows",
"[",
"i",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"oLD",
")",
"{",
"oOptions",
".",
"Size",
"=",
"Math",
".",
"floor",
"(",
"oRow",
".",
"availableCells",
"/",
"oRow",
".",
"defaultFields",
")",
";",
"}",
"if",
"(",
"iField",
"===",
"oRow",
".",
"first",
"&&",
"iField",
">",
"0",
")",
"{",
"oOptions",
".",
"Break",
"=",
"true",
";",
"if",
"(",
"iLabelSize",
">",
"0",
"&&",
"iLabelSize",
"<",
"iColumns",
"&&",
"oOptions",
".",
"Size",
"<=",
"iColumns",
"-",
"iLabelSize",
")",
"{",
"oOptions",
".",
"Space",
"=",
"iLabelSize",
";",
"}",
"}",
"if",
"(",
"iField",
"===",
"oRow",
".",
"firstDefault",
")",
"{",
"// add remaining cells to first default field",
"iRemain",
"=",
"oRow",
".",
"availableCells",
"-",
"oRow",
".",
"defaultFields",
"*",
"oOptions",
".",
"Size",
";",
"if",
"(",
"iRemain",
">",
"0",
")",
"{",
"oOptions",
".",
"Size",
"=",
"oOptions",
".",
"Size",
"+",
"iRemain",
";",
"}",
"}",
"}"
] | determine size of Field | [
"determine",
"size",
"of",
"Field"
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.layout/src/sap/ui/layout/form/ColumnLayout.js#L506-L533 |
|
3,698 | SAP/openui5 | src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js | sanitizeHistorySensitive | function sanitizeHistorySensitive(blockOfProperties) {
var elide = false;
for (var i = 0, n = blockOfProperties.length; i < n-1; ++i) {
var token = blockOfProperties[i];
if (':' === blockOfProperties[i+1]) {
elide = !(cssSchema[token].cssPropBits & CSS_PROP_BIT_ALLOWED_IN_LINK);
}
if (elide) { blockOfProperties[i] = ''; }
if (';' === token) { elide = false; }
}
return blockOfProperties.join('');
} | javascript | function sanitizeHistorySensitive(blockOfProperties) {
var elide = false;
for (var i = 0, n = blockOfProperties.length; i < n-1; ++i) {
var token = blockOfProperties[i];
if (':' === blockOfProperties[i+1]) {
elide = !(cssSchema[token].cssPropBits & CSS_PROP_BIT_ALLOWED_IN_LINK);
}
if (elide) { blockOfProperties[i] = ''; }
if (';' === token) { elide = false; }
}
return blockOfProperties.join('');
} | [
"function",
"sanitizeHistorySensitive",
"(",
"blockOfProperties",
")",
"{",
"var",
"elide",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"blockOfProperties",
".",
"length",
";",
"i",
"<",
"n",
"-",
"1",
";",
"++",
"i",
")",
"{",
"var",
"token",
"=",
"blockOfProperties",
"[",
"i",
"]",
";",
"if",
"(",
"':'",
"===",
"blockOfProperties",
"[",
"i",
"+",
"1",
"]",
")",
"{",
"elide",
"=",
"!",
"(",
"cssSchema",
"[",
"token",
"]",
".",
"cssPropBits",
"&",
"CSS_PROP_BIT_ALLOWED_IN_LINK",
")",
";",
"}",
"if",
"(",
"elide",
")",
"{",
"blockOfProperties",
"[",
"i",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"';'",
"===",
"token",
")",
"{",
"elide",
"=",
"false",
";",
"}",
"}",
"return",
"blockOfProperties",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Given a series of sanitized tokens, removes any properties that would
leak user history if allowed to style links differently depending on
whether the linked URL is in the user's browser history.
@param {Array.<string>} blockOfProperties | [
"Given",
"a",
"series",
"of",
"sanitized",
"tokens",
"removes",
"any",
"properties",
"that",
"would",
"leak",
"user",
"history",
"if",
"allowed",
"to",
"style",
"links",
"differently",
"depending",
"on",
"whether",
"the",
"linked",
"URL",
"is",
"in",
"the",
"user",
"s",
"browser",
"history",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L1493-L1504 |
3,699 | SAP/openui5 | src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js | escapeAttrib | function escapeAttrib(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
.replace(gtRe, '>').replace(quotRe, '"');
} | javascript | function escapeAttrib(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
.replace(gtRe, '>').replace(quotRe, '"');
} | [
"function",
"escapeAttrib",
"(",
"s",
")",
"{",
"return",
"(",
"''",
"+",
"s",
")",
".",
"replace",
"(",
"ampRe",
",",
"'&'",
")",
".",
"replace",
"(",
"ltRe",
",",
"'<'",
")",
".",
"replace",
"(",
"gtRe",
",",
"'>'",
")",
".",
"replace",
"(",
"quotRe",
",",
"'"'",
")",
";",
"}"
] | Escapes HTML special characters in attribute values.
{\@updoc
$ escapeAttrib('')
# ''
$ escapeAttrib('"<<&==&>>"') // Do not just escape the first occurrence.
# '"<<&==&>>"'
$ escapeAttrib('Hello <World>!')
# 'Hello <World>!'
} | [
"Escapes",
"HTML",
"special",
"characters",
"in",
"attribute",
"values",
"."
] | 8a832fca01cb1cdf8df589788e0c5723e2a33c70 | https://github.com/SAP/openui5/blob/8a832fca01cb1cdf8df589788e0c5723e2a33c70/src/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js#L2842-L2845 |
Subsets and Splits