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
58,000
pinyin/outline
vendor/transformation-matrix/applyToPoint.js
applyToPoint
function applyToPoint(matrix, point) { return { x: matrix.a * point.x + matrix.c * point.y + matrix.e, y: matrix.b * point.x + matrix.d * point.y + matrix.f }; }
javascript
function applyToPoint(matrix, point) { return { x: matrix.a * point.x + matrix.c * point.y + matrix.e, y: matrix.b * point.x + matrix.d * point.y + matrix.f }; }
[ "function", "applyToPoint", "(", "matrix", ",", "point", ")", "{", "return", "{", "x", ":", "matrix", ".", "a", "*", "point", ".", "x", "+", "matrix", ".", "c", "*", "point", ".", "y", "+", "matrix", ".", "e", ",", "y", ":", "matrix", ".", "b", "*", "point", ".", "x", "+", "matrix", ".", "d", "*", "point", ".", "y", "+", "matrix", ".", "f", "}", ";", "}" ]
Calculate a point transformed with an affine matrix @param matrix Affine matrix @param point Point @returns {{x: number, y: number}} Point
[ "Calculate", "a", "point", "transformed", "with", "an", "affine", "matrix" ]
e49f05d2f8ab384f5b1d71b2b10875cd48d41051
https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/applyToPoint.js#L15-L20
58,001
rehabstudio/fe-skeleton-testsuite
src/index.js
function(karmaSettings, resolveFn) { var testServer = new karma.Server(karmaSettings, function(exitCode) { if (typeof(resolveFn) === 'function') { resolveFn(exitCode); } else { process.exit(exitCode); } }); testServer.start(); }
javascript
function(karmaSettings, resolveFn) { var testServer = new karma.Server(karmaSettings, function(exitCode) { if (typeof(resolveFn) === 'function') { resolveFn(exitCode); } else { process.exit(exitCode); } }); testServer.start(); }
[ "function", "(", "karmaSettings", ",", "resolveFn", ")", "{", "var", "testServer", "=", "new", "karma", ".", "Server", "(", "karmaSettings", ",", "function", "(", "exitCode", ")", "{", "if", "(", "typeof", "(", "resolveFn", ")", "===", "'function'", ")", "{", "resolveFn", "(", "exitCode", ")", ";", "}", "else", "{", "process", ".", "exit", "(", "exitCode", ")", ";", "}", "}", ")", ";", "testServer", ".", "start", "(", ")", ";", "}" ]
Run the test suite with the supplied settings and callback function. @param {Object} karmaSettings - Options for Karma. @param {Function} resolveFn - Gulp async function.
[ "Run", "the", "test", "suite", "with", "the", "supplied", "settings", "and", "callback", "function", "." ]
20fb80372291d37c6054793d8eae0860f778e13e
https://github.com/rehabstudio/fe-skeleton-testsuite/blob/20fb80372291d37c6054793d8eae0860f778e13e/src/index.js#L14-L24
58,002
aronnax/pooling
src/util.js
clearObject
function clearObject(object) { var key; for (key in object) { if (object.hasOwnProperty(key)) { // Ensures only writable properties are deleted. try { delete object[key]; } catch (e) { } } } }
javascript
function clearObject(object) { var key; for (key in object) { if (object.hasOwnProperty(key)) { // Ensures only writable properties are deleted. try { delete object[key]; } catch (e) { } } } }
[ "function", "clearObject", "(", "object", ")", "{", "var", "key", ";", "for", "(", "key", "in", "object", ")", "{", "if", "(", "object", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "// Ensures only writable properties are deleted.", "try", "{", "delete", "object", "[", "key", "]", ";", "}", "catch", "(", "e", ")", "{", "}", "}", "}", "}" ]
Clear out an object of all properties @private
[ "Clear", "out", "an", "object", "of", "all", "properties" ]
0ea11afdb25abca3e0dc07dcf37fde335533d7d1
https://github.com/aronnax/pooling/blob/0ea11afdb25abca3e0dc07dcf37fde335533d7d1/src/util.js#L13-L24
58,003
yneves/node-bauer-factory
lib/stub.js
calledWith
function calledWith() { var calledWithCount = 0; var args = []; var argsLength = arguments.length; for (var i = 0; i < argsLength; i++) { args[i] = arguments[i]; } var callsLength = this._calls.length; CALLS: for (var i = 0; i < callsLength; i++) { var match = false; var called = this._calls[i]; var calledLength = called.length; if (argsLength === 0 && calledLength === 0) { match = true; } else { ARGS: for (var a = 0; a < argsLength; a++) { match = matchArgs(args[a],called[a]); if (!match) { break ARGS; } } } if (match) { calledWithCount++; } } return calledWithCount; }
javascript
function calledWith() { var calledWithCount = 0; var args = []; var argsLength = arguments.length; for (var i = 0; i < argsLength; i++) { args[i] = arguments[i]; } var callsLength = this._calls.length; CALLS: for (var i = 0; i < callsLength; i++) { var match = false; var called = this._calls[i]; var calledLength = called.length; if (argsLength === 0 && calledLength === 0) { match = true; } else { ARGS: for (var a = 0; a < argsLength; a++) { match = matchArgs(args[a],called[a]); if (!match) { break ARGS; } } } if (match) { calledWithCount++; } } return calledWithCount; }
[ "function", "calledWith", "(", ")", "{", "var", "calledWithCount", "=", "0", ";", "var", "args", "=", "[", "]", ";", "var", "argsLength", "=", "arguments", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "argsLength", ";", "i", "++", ")", "{", "args", "[", "i", "]", "=", "arguments", "[", "i", "]", ";", "}", "var", "callsLength", "=", "this", ".", "_calls", ".", "length", ";", "CALLS", ":", "for", "(", "var", "i", "=", "0", ";", "i", "<", "callsLength", ";", "i", "++", ")", "{", "var", "match", "=", "false", ";", "var", "called", "=", "this", ".", "_calls", "[", "i", "]", ";", "var", "calledLength", "=", "called", ".", "length", ";", "if", "(", "argsLength", "===", "0", "&&", "calledLength", "===", "0", ")", "{", "match", "=", "true", ";", "}", "else", "{", "ARGS", ":", "for", "(", "var", "a", "=", "0", ";", "a", "<", "argsLength", ";", "a", "++", ")", "{", "match", "=", "matchArgs", "(", "args", "[", "a", "]", ",", "called", "[", "a", "]", ")", ";", "if", "(", "!", "match", ")", "{", "break", "ARGS", ";", "}", "}", "}", "if", "(", "match", ")", "{", "calledWithCount", "++", ";", "}", "}", "return", "calledWithCount", ";", "}" ]
Count how many times stub have been called with passed arguments.
[ "Count", "how", "many", "times", "stub", "have", "been", "called", "with", "passed", "arguments", "." ]
0c54442276e742792e4c737363c1062fd2529877
https://github.com/yneves/node-bauer-factory/blob/0c54442276e742792e4c737363c1062fd2529877/lib/stub.js#L45-L72
58,004
yneves/node-bauer-factory
lib/stub.js
callbackWith
function callbackWith() { this._callbackWith = []; var length = arguments.length; for (var i = 0; i < length; i++) { var arg = arguments[i]; this._callbackWith.push(arg); } return this; }
javascript
function callbackWith() { this._callbackWith = []; var length = arguments.length; for (var i = 0; i < length; i++) { var arg = arguments[i]; this._callbackWith.push(arg); } return this; }
[ "function", "callbackWith", "(", ")", "{", "this", ".", "_callbackWith", "=", "[", "]", ";", "var", "length", "=", "arguments", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "var", "arg", "=", "arguments", "[", "i", "]", ";", "this", ".", "_callbackWith", ".", "push", "(", "arg", ")", ";", "}", "return", "this", ";", "}" ]
Defines arguments to be used by stub pass to callbacks when called.
[ "Defines", "arguments", "to", "be", "used", "by", "stub", "pass", "to", "callbacks", "when", "called", "." ]
0c54442276e742792e4c737363c1062fd2529877
https://github.com/yneves/node-bauer-factory/blob/0c54442276e742792e4c737363c1062fd2529877/lib/stub.js#L95-L103
58,005
usco/usco-stl-parser
dist/index.js
makeParsedStream
function makeParsedStream() { var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var defaults = { useWorker: _compositeDetect2.default.isBrowser === true, concat: true }; parameters = Object.assign({}, defaults, parameters); var _parameters = parameters, useWorker = _parameters.useWorker, concat = _parameters.concat; var mainStream = useWorker ? (0, _workerSpawner2.default)() : (0, _through2.default)((0, _parseStream2.default)()); // concatenate result into a single one if needed (still streaming) var endStream = concat ? (0, _combining2.default)()(mainStream, (0, _concatStream2.default)()) : mainStream; return endStream; }
javascript
function makeParsedStream() { var parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var defaults = { useWorker: _compositeDetect2.default.isBrowser === true, concat: true }; parameters = Object.assign({}, defaults, parameters); var _parameters = parameters, useWorker = _parameters.useWorker, concat = _parameters.concat; var mainStream = useWorker ? (0, _workerSpawner2.default)() : (0, _through2.default)((0, _parseStream2.default)()); // concatenate result into a single one if needed (still streaming) var endStream = concat ? (0, _combining2.default)()(mainStream, (0, _concatStream2.default)()) : mainStream; return endStream; }
[ "function", "makeParsedStream", "(", ")", "{", "var", "parameters", "=", "arguments", ".", "length", ">", "0", "&&", "arguments", "[", "0", "]", "!==", "undefined", "?", "arguments", "[", "0", "]", ":", "{", "}", ";", "var", "defaults", "=", "{", "useWorker", ":", "_compositeDetect2", ".", "default", ".", "isBrowser", "===", "true", ",", "concat", ":", "true", "}", ";", "parameters", "=", "Object", ".", "assign", "(", "{", "}", ",", "defaults", ",", "parameters", ")", ";", "var", "_parameters", "=", "parameters", ",", "useWorker", "=", "_parameters", ".", "useWorker", ",", "concat", "=", "_parameters", ".", "concat", ";", "var", "mainStream", "=", "useWorker", "?", "(", "0", ",", "_workerSpawner2", ".", "default", ")", "(", ")", ":", "(", "0", ",", "_through2", ".", "default", ")", "(", "(", "0", ",", "_parseStream2", ".", "default", ")", "(", ")", ")", ";", "// concatenate result into a single one if needed (still streaming)", "var", "endStream", "=", "concat", "?", "(", "0", ",", "_combining2", ".", "default", ")", "(", ")", "(", "mainStream", ",", "(", "0", ",", "_concatStream2", ".", "default", ")", "(", ")", ")", ":", "mainStream", ";", "return", "endStream", ";", "}" ]
parses and return a stream of parsed stl data @param {Object} parameters parameters for the parser @param {Boolean} parameters.useWorker use web workers (browser only) defaults to true in browser @param {Boolean} parameters.concat when set to true, stream outputs a single value with all combined data @return {Object} stream of parsed stl data in the form {positions:TypedArray, normals:TypedArray}
[ "parses", "and", "return", "a", "stream", "of", "parsed", "stl", "data" ]
49eb402f124723d8f74cc67f24a7017c2b99bca4
https://github.com/usco/usco-stl-parser/blob/49eb402f124723d8f74cc67f24a7017c2b99bca4/dist/index.js#L49-L67
58,006
BarzinJS/querystring-context
lib/parser.js
function (arr, val) { debug('Finding all indices...'); debug('Array: %o', arr); let indexes = []; for (let i = 0; i < arr.length; i++) { const camelCaseVal = camelCase(val), camelCaseKey = camelCase(arr[i]); if (arr[i] === val || camelCaseKey === camelCaseVal) { debug('Matched index: %s', i); indexes.push(i); } } debug('Found indices: %o', indexes); return indexes; }
javascript
function (arr, val) { debug('Finding all indices...'); debug('Array: %o', arr); let indexes = []; for (let i = 0; i < arr.length; i++) { const camelCaseVal = camelCase(val), camelCaseKey = camelCase(arr[i]); if (arr[i] === val || camelCaseKey === camelCaseVal) { debug('Matched index: %s', i); indexes.push(i); } } debug('Found indices: %o', indexes); return indexes; }
[ "function", "(", "arr", ",", "val", ")", "{", "debug", "(", "'Finding all indices...'", ")", ";", "debug", "(", "'Array: %o'", ",", "arr", ")", ";", "let", "indexes", "=", "[", "]", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "const", "camelCaseVal", "=", "camelCase", "(", "val", ")", ",", "camelCaseKey", "=", "camelCase", "(", "arr", "[", "i", "]", ")", ";", "if", "(", "arr", "[", "i", "]", "===", "val", "||", "camelCaseKey", "===", "camelCaseVal", ")", "{", "debug", "(", "'Matched index: %s'", ",", "i", ")", ";", "indexes", ".", "push", "(", "i", ")", ";", "}", "}", "debug", "(", "'Found indices: %o'", ",", "indexes", ")", ";", "return", "indexes", ";", "}" ]
Find all indices of a value in an array @param {Array<string>} arr Array to search in @param {string} val Target value @returns {Array<number>} List of indices
[ "Find", "all", "indices", "of", "a", "value", "in", "an", "array" ]
9e082778ac484660d159b4687fcf8a012cb9d903
https://github.com/BarzinJS/querystring-context/blob/9e082778ac484660d159b4687fcf8a012cb9d903/lib/parser.js#L104-L128
58,007
BarzinJS/querystring-context
lib/parser.js
function (value) { if (!Array.isArray(value)) { // null/undefined or anything else must be safely convert to string value = value + ''; } if (Array.isArray(value)) { // map all values again value = value.map(v => this.parseValue(v)); } else if (validator.isNumeric(value)) { value = value * 1; // parse as a number } else if (validator.isBoolean(value)) { value = (value === 'true'); } else { // convert to JS date const date = validator.toDate(value); // date is valid, assign if (date !== null) { value = date; } if (value === 'null') { value = null; } if (value === 'undefined') { value = undefined; } } return value; }
javascript
function (value) { if (!Array.isArray(value)) { // null/undefined or anything else must be safely convert to string value = value + ''; } if (Array.isArray(value)) { // map all values again value = value.map(v => this.parseValue(v)); } else if (validator.isNumeric(value)) { value = value * 1; // parse as a number } else if (validator.isBoolean(value)) { value = (value === 'true'); } else { // convert to JS date const date = validator.toDate(value); // date is valid, assign if (date !== null) { value = date; } if (value === 'null') { value = null; } if (value === 'undefined') { value = undefined; } } return value; }
[ "function", "(", "value", ")", "{", "if", "(", "!", "Array", ".", "isArray", "(", "value", ")", ")", "{", "// null/undefined or anything else must be safely convert to string", "value", "=", "value", "+", "''", ";", "}", "if", "(", "Array", ".", "isArray", "(", "value", ")", ")", "{", "// map all values again", "value", "=", "value", ".", "map", "(", "v", "=>", "this", ".", "parseValue", "(", "v", ")", ")", ";", "}", "else", "if", "(", "validator", ".", "isNumeric", "(", "value", ")", ")", "{", "value", "=", "value", "*", "1", ";", "// parse as a number", "}", "else", "if", "(", "validator", ".", "isBoolean", "(", "value", ")", ")", "{", "value", "=", "(", "value", "===", "'true'", ")", ";", "}", "else", "{", "// convert to JS date", "const", "date", "=", "validator", ".", "toDate", "(", "value", ")", ";", "// date is valid, assign", "if", "(", "date", "!==", "null", ")", "{", "value", "=", "date", ";", "}", "if", "(", "value", "===", "'null'", ")", "{", "value", "=", "null", ";", "}", "if", "(", "value", "===", "'undefined'", ")", "{", "value", "=", "undefined", ";", "}", "}", "return", "value", ";", "}" ]
Parse string to a parsable type @param {string} value Value to parse @returns {string|number|boolean|date} Parsed value
[ "Parse", "string", "to", "a", "parsable", "type" ]
9e082778ac484660d159b4687fcf8a012cb9d903
https://github.com/BarzinJS/querystring-context/blob/9e082778ac484660d159b4687fcf8a012cb9d903/lib/parser.js#L201-L246
58,008
BarzinJS/querystring-context
lib/parser.js
function (obj, options) { debug('Parsing properties...'); debug('Object: %o', obj); Object.keys(obj) .map(key => { let value = obj[key]; debug('Value: %o', value); // parse current value value = helpers.parseValue(value); debug('Parsed value: %o', value); // replace value with the updated one obj[key] = value; }); debug('Parsed options: %o', obj); return obj; }
javascript
function (obj, options) { debug('Parsing properties...'); debug('Object: %o', obj); Object.keys(obj) .map(key => { let value = obj[key]; debug('Value: %o', value); // parse current value value = helpers.parseValue(value); debug('Parsed value: %o', value); // replace value with the updated one obj[key] = value; }); debug('Parsed options: %o', obj); return obj; }
[ "function", "(", "obj", ",", "options", ")", "{", "debug", "(", "'Parsing properties...'", ")", ";", "debug", "(", "'Object: %o'", ",", "obj", ")", ";", "Object", ".", "keys", "(", "obj", ")", ".", "map", "(", "key", "=>", "{", "let", "value", "=", "obj", "[", "key", "]", ";", "debug", "(", "'Value: %o'", ",", "value", ")", ";", "// parse current value", "value", "=", "helpers", ".", "parseValue", "(", "value", ")", ";", "debug", "(", "'Parsed value: %o'", ",", "value", ")", ";", "// replace value with the updated one", "obj", "[", "key", "]", "=", "value", ";", "}", ")", ";", "debug", "(", "'Parsed options: %o'", ",", "obj", ")", ";", "return", "obj", ";", "}" ]
Parse properties of an object @param {any} obj Target object @param {any} options Parser options @returns {any} Parsed options
[ "Parse", "properties", "of", "an", "object" ]
9e082778ac484660d159b4687fcf8a012cb9d903
https://github.com/BarzinJS/querystring-context/blob/9e082778ac484660d159b4687fcf8a012cb9d903/lib/parser.js#L254-L279
58,009
skylarkutils/skylark-utils
examples/images/progress/progress.js
onProgress
function onProgress( e ) { // change class if the image is loaded or broken e.img.parentNode.className = e.isLoaded ? '' : 'is-broken'; // update progress element loadedImageCount++; updateProgress( loadedImageCount ); }
javascript
function onProgress( e ) { // change class if the image is loaded or broken e.img.parentNode.className = e.isLoaded ? '' : 'is-broken'; // update progress element loadedImageCount++; updateProgress( loadedImageCount ); }
[ "function", "onProgress", "(", "e", ")", "{", "// change class if the image is loaded or broken", "e", ".", "img", ".", "parentNode", ".", "className", "=", "e", ".", "isLoaded", "?", "''", ":", "'is-broken'", ";", "// update progress element", "loadedImageCount", "++", ";", "updateProgress", "(", "loadedImageCount", ")", ";", "}" ]
triggered after each item is loaded
[ "triggered", "after", "each", "item", "is", "loaded" ]
ef082bb53b162b4a2c6992ef07a3e32553f6aed5
https://github.com/skylarkutils/skylark-utils/blob/ef082bb53b162b4a2c6992ef07a3e32553f6aed5/examples/images/progress/progress.js#L100-L106
58,010
lakenen/node-box-view
index.js
determineFilename
function determineFilename(file) { var filename, filenameMatch; if (file.hasOwnProperty('httpVersion')) { // it's an http response // first let's check if there's a content-disposition header... if (file.headers['content-disposition']) { filenameMatch = /filename=(.*)/.exec(file.headers['content-disposition']); filename = filenameMatch[1]; } if (!filename) { // try to get the path of the request url filename = path.basename(file.client._httpMessage.path); } } else if (file.path) { // it looks like a file, let's just get the path filename = path.basename(file.path); } return filename || 'untitled document'; }
javascript
function determineFilename(file) { var filename, filenameMatch; if (file.hasOwnProperty('httpVersion')) { // it's an http response // first let's check if there's a content-disposition header... if (file.headers['content-disposition']) { filenameMatch = /filename=(.*)/.exec(file.headers['content-disposition']); filename = filenameMatch[1]; } if (!filename) { // try to get the path of the request url filename = path.basename(file.client._httpMessage.path); } } else if (file.path) { // it looks like a file, let's just get the path filename = path.basename(file.path); } return filename || 'untitled document'; }
[ "function", "determineFilename", "(", "file", ")", "{", "var", "filename", ",", "filenameMatch", ";", "if", "(", "file", ".", "hasOwnProperty", "(", "'httpVersion'", ")", ")", "{", "// it's an http response", "// first let's check if there's a content-disposition header...", "if", "(", "file", ".", "headers", "[", "'content-disposition'", "]", ")", "{", "filenameMatch", "=", "/", "filename=(.*)", "/", ".", "exec", "(", "file", ".", "headers", "[", "'content-disposition'", "]", ")", ";", "filename", "=", "filenameMatch", "[", "1", "]", ";", "}", "if", "(", "!", "filename", ")", "{", "// try to get the path of the request url", "filename", "=", "path", ".", "basename", "(", "file", ".", "client", ".", "_httpMessage", ".", "path", ")", ";", "}", "}", "else", "if", "(", "file", ".", "path", ")", "{", "// it looks like a file, let's just get the path", "filename", "=", "path", ".", "basename", "(", "file", ".", "path", ")", ";", "}", "return", "filename", "||", "'untitled document'", ";", "}" ]
Try to figure out the filename for the given file @param {Stream} file The file stream @returns {string} The guessed filename
[ "Try", "to", "figure", "out", "the", "filename", "for", "the", "given", "file" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L57-L77
58,011
lakenen/node-box-view
index.js
handleError
function handleError(body, response, callback) { var error; if (!body) { response.pipe(concat(function (body) { body = parseJSONBody(body); error = body.message || statusText(response.statusCode); callback(new Error(error), body, response); })); } else { error = body.message || statusText(response.statusCode); callback(new Error(error), body, response); } }
javascript
function handleError(body, response, callback) { var error; if (!body) { response.pipe(concat(function (body) { body = parseJSONBody(body); error = body.message || statusText(response.statusCode); callback(new Error(error), body, response); })); } else { error = body.message || statusText(response.statusCode); callback(new Error(error), body, response); } }
[ "function", "handleError", "(", "body", ",", "response", ",", "callback", ")", "{", "var", "error", ";", "if", "(", "!", "body", ")", "{", "response", ".", "pipe", "(", "concat", "(", "function", "(", "body", ")", "{", "body", "=", "parseJSONBody", "(", "body", ")", ";", "error", "=", "body", ".", "message", "||", "statusText", "(", "response", ".", "statusCode", ")", ";", "callback", "(", "new", "Error", "(", "error", ")", ",", "body", ",", "response", ")", ";", "}", ")", ")", ";", "}", "else", "{", "error", "=", "body", ".", "message", "||", "statusText", "(", "response", ".", "statusCode", ")", ";", "callback", "(", "new", "Error", "(", "error", ")", ",", "body", ",", "response", ")", ";", "}", "}" ]
Create an error object from the response and call the callback function @param {Object} body The parsed response body (or null if not yet parsed) @param {Response} response The HTTP response object @param {Function} callback Function to call with the resulting error object @returns {void}
[ "Create", "an", "error", "object", "from", "the", "response", "and", "call", "the", "callback", "function" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L117-L129
58,012
lakenen/node-box-view
index.js
createResponseHandler
function createResponseHandler(callback, okStatusCodes, noBuffer, retryFn) { if (typeof callback !== 'function') { callback = function () {}; } if (typeof okStatusCodes === 'function') { retryFn = okStatusCodes; okStatusCodes = null; noBuffer = retryFn; } if (typeof noBuffer === 'function') { retryFn = noBuffer; noBuffer = false; } okStatusCodes = okStatusCodes || [200]; /** * Retry the request if a retry function and retry-after headers are present * @param {HTTPResponse} response The response object * @returns {void} */ function retry(response) { var retryAfter = response.headers['retry-after']; if (typeof retryFn === 'function' && retryAfter) { retryAfter = parseInt(retryAfter, 10); setTimeout(retryFn, retryAfter * 1000); return true; } return false; } function handleResponse(response, body) { var error; // the handler expects a parsed response body if (noBuffer !== true && typeof body === 'undefined') { response.pipe(concat(function (body) { handleResponse(response, parseJSONBody(body)); })); return; } if (okStatusCodes.indexOf(response.statusCode) > -1) { if (!retry(response)) { if (noBuffer) { callback(null, response); } else { callback(null, body, response); } } } else { if (response.statusCode === 429) { if (retry(response)) { return; } } handleError(body, response, callback); } } return function (error, response) { if (error) { callback(error, response); } else { handleResponse(response); } }; }
javascript
function createResponseHandler(callback, okStatusCodes, noBuffer, retryFn) { if (typeof callback !== 'function') { callback = function () {}; } if (typeof okStatusCodes === 'function') { retryFn = okStatusCodes; okStatusCodes = null; noBuffer = retryFn; } if (typeof noBuffer === 'function') { retryFn = noBuffer; noBuffer = false; } okStatusCodes = okStatusCodes || [200]; /** * Retry the request if a retry function and retry-after headers are present * @param {HTTPResponse} response The response object * @returns {void} */ function retry(response) { var retryAfter = response.headers['retry-after']; if (typeof retryFn === 'function' && retryAfter) { retryAfter = parseInt(retryAfter, 10); setTimeout(retryFn, retryAfter * 1000); return true; } return false; } function handleResponse(response, body) { var error; // the handler expects a parsed response body if (noBuffer !== true && typeof body === 'undefined') { response.pipe(concat(function (body) { handleResponse(response, parseJSONBody(body)); })); return; } if (okStatusCodes.indexOf(response.statusCode) > -1) { if (!retry(response)) { if (noBuffer) { callback(null, response); } else { callback(null, body, response); } } } else { if (response.statusCode === 429) { if (retry(response)) { return; } } handleError(body, response, callback); } } return function (error, response) { if (error) { callback(error, response); } else { handleResponse(response); } }; }
[ "function", "createResponseHandler", "(", "callback", ",", "okStatusCodes", ",", "noBuffer", ",", "retryFn", ")", "{", "if", "(", "typeof", "callback", "!==", "'function'", ")", "{", "callback", "=", "function", "(", ")", "{", "}", ";", "}", "if", "(", "typeof", "okStatusCodes", "===", "'function'", ")", "{", "retryFn", "=", "okStatusCodes", ";", "okStatusCodes", "=", "null", ";", "noBuffer", "=", "retryFn", ";", "}", "if", "(", "typeof", "noBuffer", "===", "'function'", ")", "{", "retryFn", "=", "noBuffer", ";", "noBuffer", "=", "false", ";", "}", "okStatusCodes", "=", "okStatusCodes", "||", "[", "200", "]", ";", "/**\n * Retry the request if a retry function and retry-after headers are present\n * @param {HTTPResponse} response The response object\n * @returns {void}\n */", "function", "retry", "(", "response", ")", "{", "var", "retryAfter", "=", "response", ".", "headers", "[", "'retry-after'", "]", ";", "if", "(", "typeof", "retryFn", "===", "'function'", "&&", "retryAfter", ")", "{", "retryAfter", "=", "parseInt", "(", "retryAfter", ",", "10", ")", ";", "setTimeout", "(", "retryFn", ",", "retryAfter", "*", "1000", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}", "function", "handleResponse", "(", "response", ",", "body", ")", "{", "var", "error", ";", "// the handler expects a parsed response body", "if", "(", "noBuffer", "!==", "true", "&&", "typeof", "body", "===", "'undefined'", ")", "{", "response", ".", "pipe", "(", "concat", "(", "function", "(", "body", ")", "{", "handleResponse", "(", "response", ",", "parseJSONBody", "(", "body", ")", ")", ";", "}", ")", ")", ";", "return", ";", "}", "if", "(", "okStatusCodes", ".", "indexOf", "(", "response", ".", "statusCode", ")", ">", "-", "1", ")", "{", "if", "(", "!", "retry", "(", "response", ")", ")", "{", "if", "(", "noBuffer", ")", "{", "callback", "(", "null", ",", "response", ")", ";", "}", "else", "{", "callback", "(", "null", ",", "body", ",", "response", ")", ";", "}", "}", "}", "else", "{", "if", "(", "response", ".", "statusCode", "===", "429", ")", "{", "if", "(", "retry", "(", "response", ")", ")", "{", "return", ";", "}", "}", "handleError", "(", "body", ",", "response", ",", "callback", ")", ";", "}", "}", "return", "function", "(", "error", ",", "response", ")", "{", "if", "(", "error", ")", "{", "callback", "(", "error", ",", "response", ")", ";", "}", "else", "{", "handleResponse", "(", "response", ")", ";", "}", "}", ";", "}" ]
Return an http response handler for API calls @param {Function} callback The callback method to call @param {Array} okStatusCodes (optional) HTTP status codes to use as OK (default: [200]) @param {Boolean} noBuffer (optional) If true, the response will not be buffered and JSON parsed (unless error), default: false @param {Function} retryFn (optional) If defined, function to call when receiving a Retry-After header @returns {Function} The response handler
[ "Return", "an", "http", "response", "handler", "for", "API", "calls" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L139-L208
58,013
lakenen/node-box-view
index.js
retry
function retry(response) { var retryAfter = response.headers['retry-after']; if (typeof retryFn === 'function' && retryAfter) { retryAfter = parseInt(retryAfter, 10); setTimeout(retryFn, retryAfter * 1000); return true; } return false; }
javascript
function retry(response) { var retryAfter = response.headers['retry-after']; if (typeof retryFn === 'function' && retryAfter) { retryAfter = parseInt(retryAfter, 10); setTimeout(retryFn, retryAfter * 1000); return true; } return false; }
[ "function", "retry", "(", "response", ")", "{", "var", "retryAfter", "=", "response", ".", "headers", "[", "'retry-after'", "]", ";", "if", "(", "typeof", "retryFn", "===", "'function'", "&&", "retryAfter", ")", "{", "retryAfter", "=", "parseInt", "(", "retryAfter", ",", "10", ")", ";", "setTimeout", "(", "retryFn", ",", "retryAfter", "*", "1000", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Retry the request if a retry function and retry-after headers are present @param {HTTPResponse} response The response object @returns {void}
[ "Retry", "the", "request", "if", "a", "retry", "function", "and", "retry", "-", "after", "headers", "are", "present" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L161-L169
58,014
lakenen/node-box-view
index.js
function (options, callback) { var query, handler, retry = false, params, args = arguments; if (typeof options === 'function') { callback = options; params = {}; } else { params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.list.apply(this, args); }.bind(this); if (params['created_before']) { params['created_before'] = getTimestamp(params['created_before']); } if (params['created_after']) { params['created_after'] = getTimestamp(params['created_after']); } query = querystring.stringify(params); if (query) { query = '?' + query; } handler = createResponseHandler(callback, retry); return req(client.documentsURL + query, handler); }
javascript
function (options, callback) { var query, handler, retry = false, params, args = arguments; if (typeof options === 'function') { callback = options; params = {}; } else { params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.list.apply(this, args); }.bind(this); if (params['created_before']) { params['created_before'] = getTimestamp(params['created_before']); } if (params['created_after']) { params['created_after'] = getTimestamp(params['created_after']); } query = querystring.stringify(params); if (query) { query = '?' + query; } handler = createResponseHandler(callback, retry); return req(client.documentsURL + query, handler); }
[ "function", "(", "options", ",", "callback", ")", "{", "var", "query", ",", "handler", ",", "retry", "=", "false", ",", "params", ",", "args", "=", "arguments", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "params", "=", "{", "}", ";", "}", "else", "{", "params", "=", "extend", "(", "{", "}", ",", "options", ".", "params", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "list", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "if", "(", "params", "[", "'created_before'", "]", ")", "{", "params", "[", "'created_before'", "]", "=", "getTimestamp", "(", "params", "[", "'created_before'", "]", ")", ";", "}", "if", "(", "params", "[", "'created_after'", "]", ")", "{", "params", "[", "'created_after'", "]", "=", "getTimestamp", "(", "params", "[", "'created_after'", "]", ")", ";", "}", "query", "=", "querystring", ".", "stringify", "(", "params", ")", ";", "if", "(", "query", ")", "{", "query", "=", "'?'", "+", "query", ";", "}", "handler", "=", "createResponseHandler", "(", "callback", ",", "retry", ")", ";", "return", "req", "(", "client", ".", "documentsURL", "+", "query", ",", "handler", ")", ";", "}" ]
Fetch a list of documents uploaded using this API key @param {Object} [options] List options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Object} [options.params] URL parameters @param {int} [options.params.limit] The number of documents to return (default: 10, max: 50) @param {Date} [options.params.created_before] An upper limit on the creation timestamps of documents returned (default: now) @param {Date} [options.params.created_after] A lower limit on the creation timestamps of documents returned @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Fetch", "a", "list", "of", "documents", "uploaded", "using", "this", "API", "key" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L241-L276
58,015
lakenen/node-box-view
index.js
function (id, options, callback) { var query = '', handler, retry = false, fields, args = arguments; if (typeof options === 'function') { callback = options; fields = ''; } else { options = extend({}, options); fields = options.fields || ''; retry = options.retry; } if (Array.isArray(fields)) { fields = fields.join(','); } retry = (retry === true) && function () { this.get.apply(this, args); }.bind(this); if (fields) { query = '?' + querystring.stringify({ fields: fields }); } handler = createResponseHandler(callback, retry); return req(client.documentsURL + '/' + id + query, handler); }
javascript
function (id, options, callback) { var query = '', handler, retry = false, fields, args = arguments; if (typeof options === 'function') { callback = options; fields = ''; } else { options = extend({}, options); fields = options.fields || ''; retry = options.retry; } if (Array.isArray(fields)) { fields = fields.join(','); } retry = (retry === true) && function () { this.get.apply(this, args); }.bind(this); if (fields) { query = '?' + querystring.stringify({ fields: fields }); } handler = createResponseHandler(callback, retry); return req(client.documentsURL + '/' + id + query, handler); }
[ "function", "(", "id", ",", "options", ",", "callback", ")", "{", "var", "query", "=", "''", ",", "handler", ",", "retry", "=", "false", ",", "fields", ",", "args", "=", "arguments", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "fields", "=", "''", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "fields", "=", "options", ".", "fields", "||", "''", ";", "retry", "=", "options", ".", "retry", ";", "}", "if", "(", "Array", ".", "isArray", "(", "fields", ")", ")", "{", "fields", "=", "fields", ".", "join", "(", "','", ")", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "get", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "if", "(", "fields", ")", "{", "query", "=", "'?'", "+", "querystring", ".", "stringify", "(", "{", "fields", ":", "fields", "}", ")", ";", "}", "handler", "=", "createResponseHandler", "(", "callback", ",", "retry", ")", ";", "return", "req", "(", "client", ".", "documentsURL", "+", "'/'", "+", "id", "+", "query", ",", "handler", ")", ";", "}" ]
Fetch the metadata for a single document @param {String} id The document uuid @param {Object} [options] Get options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {String|Array} [options.fields] Array of strings or comma-separated string of fields to return. id and type are always returned. @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Fetch", "the", "metadata", "for", "a", "single", "document" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L287-L320
58,016
lakenen/node-box-view
index.js
function (id, data, options, callback) { var args = arguments, r, handler, retry = false, requestOptions = { method: 'PUT', headers: { 'content-type': 'application/json' } }; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.update.apply(this, args); }.bind(this); handler = createResponseHandler(callback, retry); r = req(client.documentsURL + '/' + id, requestOptions, handler); data = new Buffer(JSON.stringify(data)); r.setHeader('content-length', data.length); r.end(data); return r; }
javascript
function (id, data, options, callback) { var args = arguments, r, handler, retry = false, requestOptions = { method: 'PUT', headers: { 'content-type': 'application/json' } }; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.update.apply(this, args); }.bind(this); handler = createResponseHandler(callback, retry); r = req(client.documentsURL + '/' + id, requestOptions, handler); data = new Buffer(JSON.stringify(data)); r.setHeader('content-length', data.length); r.end(data); return r; }
[ "function", "(", "id", ",", "data", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "arguments", ",", "r", ",", "handler", ",", "retry", "=", "false", ",", "requestOptions", "=", "{", "method", ":", "'PUT'", ",", "headers", ":", "{", "'content-type'", ":", "'application/json'", "}", "}", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "update", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "handler", "=", "createResponseHandler", "(", "callback", ",", "retry", ")", ";", "r", "=", "req", "(", "client", ".", "documentsURL", "+", "'/'", "+", "id", ",", "requestOptions", ",", "handler", ")", ";", "data", "=", "new", "Buffer", "(", "JSON", ".", "stringify", "(", "data", ")", ")", ";", "r", ".", "setHeader", "(", "'content-length'", ",", "data", ".", "length", ")", ";", "r", ".", "end", "(", "data", ")", ";", "return", "r", ";", "}" ]
Update the metadata for a single document @param {String} id The document uuid @param {Object} data The new metadata @param {Object} [options] Update options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Update", "the", "metadata", "for", "a", "single", "document" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L331-L361
58,017
lakenen/node-box-view
index.js
function (id, options, callback) { var args = arguments, retry = false, handler; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.delete.apply(this, args); }.bind(this); handler = createResponseHandler(callback, [204], true, retry); return req(client.documentsURL + '/' + id, { method: 'DELETE' }, handler); }
javascript
function (id, options, callback) { var args = arguments, retry = false, handler; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.delete.apply(this, args); }.bind(this); handler = createResponseHandler(callback, [204], true, retry); return req(client.documentsURL + '/' + id, { method: 'DELETE' }, handler); }
[ "function", "(", "id", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "arguments", ",", "retry", "=", "false", ",", "handler", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "delete", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "handler", "=", "createResponseHandler", "(", "callback", ",", "[", "204", "]", ",", "true", ",", "retry", ")", ";", "return", "req", "(", "client", ".", "documentsURL", "+", "'/'", "+", "id", ",", "{", "method", ":", "'DELETE'", "}", ",", "handler", ")", ";", "}" ]
Delete a single document @param {String} id The document uuid @param {Object} [options] Delete options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Delete", "a", "single", "document" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L371-L390
58,018
lakenen/node-box-view
index.js
function (file, options, callback) { var args = arguments, r, param, form, handler, params, retry = false, requestOptions = { method: 'POST' }; if (typeof file === 'string') { file = fs.createReadStream(file); } if (typeof options === 'function') { callback = options; params = {}; } else { options = extend({}, options); params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.uploadFile.apply(this, args); }.bind(this); // filename is required for the form to work properly, so try to // figure out a name... if (!params.name) { params.name = determineFilename(file); } // if the file is a stream, we cannot retry if (retry && file.readable) { throw new Error('Retry option is not supported for streams.'); } handler = createResponseHandler(callback, [200, 202], retry); form = new FormData(); for (param in params) { if (params.hasOwnProperty(param)) { form.append(param, params[param].toString()); } } form.append('file', file, { filename: params.name }); extend(true, requestOptions, { headers: form.getHeaders() }); r = req(client.documentsUploadURL, requestOptions, handler); form.pipe(r); return r; }
javascript
function (file, options, callback) { var args = arguments, r, param, form, handler, params, retry = false, requestOptions = { method: 'POST' }; if (typeof file === 'string') { file = fs.createReadStream(file); } if (typeof options === 'function') { callback = options; params = {}; } else { options = extend({}, options); params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.uploadFile.apply(this, args); }.bind(this); // filename is required for the form to work properly, so try to // figure out a name... if (!params.name) { params.name = determineFilename(file); } // if the file is a stream, we cannot retry if (retry && file.readable) { throw new Error('Retry option is not supported for streams.'); } handler = createResponseHandler(callback, [200, 202], retry); form = new FormData(); for (param in params) { if (params.hasOwnProperty(param)) { form.append(param, params[param].toString()); } } form.append('file', file, { filename: params.name }); extend(true, requestOptions, { headers: form.getHeaders() }); r = req(client.documentsUploadURL, requestOptions, handler); form.pipe(r); return r; }
[ "function", "(", "file", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "arguments", ",", "r", ",", "param", ",", "form", ",", "handler", ",", "params", ",", "retry", "=", "false", ",", "requestOptions", "=", "{", "method", ":", "'POST'", "}", ";", "if", "(", "typeof", "file", "===", "'string'", ")", "{", "file", "=", "fs", ".", "createReadStream", "(", "file", ")", ";", "}", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "params", "=", "{", "}", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "params", "=", "extend", "(", "{", "}", ",", "options", ".", "params", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "uploadFile", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "// filename is required for the form to work properly, so try to", "// figure out a name...", "if", "(", "!", "params", ".", "name", ")", "{", "params", ".", "name", "=", "determineFilename", "(", "file", ")", ";", "}", "// if the file is a stream, we cannot retry", "if", "(", "retry", "&&", "file", ".", "readable", ")", "{", "throw", "new", "Error", "(", "'Retry option is not supported for streams.'", ")", ";", "}", "handler", "=", "createResponseHandler", "(", "callback", ",", "[", "200", ",", "202", "]", ",", "retry", ")", ";", "form", "=", "new", "FormData", "(", ")", ";", "for", "(", "param", "in", "params", ")", "{", "if", "(", "params", ".", "hasOwnProperty", "(", "param", ")", ")", "{", "form", ".", "append", "(", "param", ",", "params", "[", "param", "]", ".", "toString", "(", ")", ")", ";", "}", "}", "form", ".", "append", "(", "'file'", ",", "file", ",", "{", "filename", ":", "params", ".", "name", "}", ")", ";", "extend", "(", "true", ",", "requestOptions", ",", "{", "headers", ":", "form", ".", "getHeaders", "(", ")", "}", ")", ";", "r", "=", "req", "(", "client", ".", "documentsUploadURL", ",", "requestOptions", ",", "handler", ")", ";", "form", ".", "pipe", "(", "r", ")", ";", "return", "r", ";", "}" ]
Do a multipart upload from a file path or readable stream @param {String|Stream|Buffer} file A path to a file to read, a readable stream, or a Buffer @param {Object} [options] Upload options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Object} [options.params] Upload parameters @param {String} [options.params.name] The name of the file @param {String} [options.params.thumbnails] Comma-separated list of thumbnail dimensions of the format {width}x{height} e.g. 128×128,256×256 – width can be between 16 and 1024, height between 16 and 768 @param {Boolean} [options.params.non_svg] Whether to also create the non-svg version of the document @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Do", "a", "multipart", "upload", "from", "a", "file", "path", "or", "readable", "stream" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L404-L461
58,019
lakenen/node-box-view
index.js
function (url, options, callback) { var args = arguments, r, handler, params, data = '', retry = false, requestOptions = { method: 'POST', headers: { 'content-type': 'application/json' } }; if (typeof options === 'function') { callback = options; params = {}; } else { options = extend({}, options); params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.uploadURL.apply(this, args); }.bind(this); if (!params.name) { params.name = path.basename(url); } params.url = url; handler = createResponseHandler(callback, [200, 202], retry); r = req(client.documentsURL, requestOptions, handler); data = new Buffer(JSON.stringify(params)); r.setHeader('content-length', data.length); r.end(data); return r; }
javascript
function (url, options, callback) { var args = arguments, r, handler, params, data = '', retry = false, requestOptions = { method: 'POST', headers: { 'content-type': 'application/json' } }; if (typeof options === 'function') { callback = options; params = {}; } else { options = extend({}, options); params = extend({}, options.params); retry = options.retry; } retry = (retry === true) && function () { this.uploadURL.apply(this, args); }.bind(this); if (!params.name) { params.name = path.basename(url); } params.url = url; handler = createResponseHandler(callback, [200, 202], retry); r = req(client.documentsURL, requestOptions, handler); data = new Buffer(JSON.stringify(params)); r.setHeader('content-length', data.length); r.end(data); return r; }
[ "function", "(", "url", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "arguments", ",", "r", ",", "handler", ",", "params", ",", "data", "=", "''", ",", "retry", "=", "false", ",", "requestOptions", "=", "{", "method", ":", "'POST'", ",", "headers", ":", "{", "'content-type'", ":", "'application/json'", "}", "}", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "params", "=", "{", "}", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "params", "=", "extend", "(", "{", "}", ",", "options", ".", "params", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "uploadURL", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "if", "(", "!", "params", ".", "name", ")", "{", "params", ".", "name", "=", "path", ".", "basename", "(", "url", ")", ";", "}", "params", ".", "url", "=", "url", ";", "handler", "=", "createResponseHandler", "(", "callback", ",", "[", "200", ",", "202", "]", ",", "retry", ")", ";", "r", "=", "req", "(", "client", ".", "documentsURL", ",", "requestOptions", ",", "handler", ")", ";", "data", "=", "new", "Buffer", "(", "JSON", ".", "stringify", "(", "params", ")", ")", ";", "r", ".", "setHeader", "(", "'content-length'", ",", "data", ".", "length", ")", ";", "r", ".", "end", "(", "data", ")", ";", "return", "r", ";", "}" ]
Do a URL upload of a file @param {String} url A URL to a publicly-accessible file to upload @param {Object} [options] Upload options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Object} [options.params] Upload parameters @param {String} [options.params.name] The name of the file @param {String} [options.params.thumbnails] Comma-separated list of thumbnail dimensions of the format {width}x{height} e.g. 128×128,256×256 – width can be between 16 and 1024, height between 16 and 768 @param {Boolean} [options.params.non_svg] Whether to also create the non-svg version of the document @param {Function} [callback] A callback to call with the response data (or error) @returns {Request}
[ "Do", "a", "URL", "upload", "of", "a", "file" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L475-L516
58,020
lakenen/node-box-view
index.js
function (id, width, height, options, callback) { var args = arguments, url, query, retry = false, params, handler; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.getThumbnail.apply(this, args); }.bind(this); params = { width: width, height: height }; handler = createResponseHandler(callback, [200, 202], true, retry); query = querystring.stringify(params); url = client.documentsURL + '/' + id + '/thumbnail?' + query; return req(url, handler); }
javascript
function (id, width, height, options, callback) { var args = arguments, url, query, retry = false, params, handler; if (typeof options === 'function') { callback = options; } else { options = extend({}, options); retry = options.retry; } retry = (retry === true) && function () { this.getThumbnail.apply(this, args); }.bind(this); params = { width: width, height: height }; handler = createResponseHandler(callback, [200, 202], true, retry); query = querystring.stringify(params); url = client.documentsURL + '/' + id + '/thumbnail?' + query; return req(url, handler); }
[ "function", "(", "id", ",", "width", ",", "height", ",", "options", ",", "callback", ")", "{", "var", "args", "=", "arguments", ",", "url", ",", "query", ",", "retry", "=", "false", ",", "params", ",", "handler", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "callback", "=", "options", ";", "}", "else", "{", "options", "=", "extend", "(", "{", "}", ",", "options", ")", ";", "retry", "=", "options", ".", "retry", ";", "}", "retry", "=", "(", "retry", "===", "true", ")", "&&", "function", "(", ")", "{", "this", ".", "getThumbnail", ".", "apply", "(", "this", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ";", "params", "=", "{", "width", ":", "width", ",", "height", ":", "height", "}", ";", "handler", "=", "createResponseHandler", "(", "callback", ",", "[", "200", ",", "202", "]", ",", "true", ",", "retry", ")", ";", "query", "=", "querystring", ".", "stringify", "(", "params", ")", ";", "url", "=", "client", ".", "documentsURL", "+", "'/'", "+", "id", "+", "'/thumbnail?'", "+", "query", ";", "return", "req", "(", "url", ",", "handler", ")", ";", "}" ]
Fetches a thumbnail for the given document id @param {string} id The document uuid @param {int} width The thumbnail width @param {int} height The thumbnail height @param {Object} [options] Content options @param {boolean} [options.retry] Whether to retry the request after 'retry-after' seconds if the retry-after header is sent @param {Function} [callback] A callback to call with the response (or error) @returns {Request}
[ "Fetches", "a", "thumbnail", "for", "the", "given", "document", "id" ]
5888e4d60cd6bdc3b656724bee2dd56b6adf32ec
https://github.com/lakenen/node-box-view/blob/5888e4d60cd6bdc3b656724bee2dd56b6adf32ec/index.js#L568-L597
58,021
nutella-framework/nutella_lib.js
src/run_net_bin.js
function(main_nutella, net_sub_module) { // Store a reference to the main module this.nutella = main_nutella; this.net = net_sub_module; this.file_mngr_url = 'http://' + main_nutella.mqtt_client.getHost() + ':57882'; }
javascript
function(main_nutella, net_sub_module) { // Store a reference to the main module this.nutella = main_nutella; this.net = net_sub_module; this.file_mngr_url = 'http://' + main_nutella.mqtt_client.getHost() + ':57882'; }
[ "function", "(", "main_nutella", ",", "net_sub_module", ")", "{", "// Store a reference to the main module", "this", ".", "nutella", "=", "main_nutella", ";", "this", ".", "net", "=", "net_sub_module", ";", "this", ".", "file_mngr_url", "=", "'http://'", "+", "main_nutella", ".", "mqtt_client", ".", "getHost", "(", ")", "+", "':57882'", ";", "}" ]
Run-level binary network APIs for nutella @param main_nutella @constructor
[ "Run", "-", "level", "binary", "network", "APIs", "for", "nutella" ]
b3a3406a407e2a1ada6edcc503b70991f9cb249b
https://github.com/nutella-framework/nutella_lib.js/blob/b3a3406a407e2a1ada6edcc503b70991f9cb249b/src/run_net_bin.js#L14-L19
58,022
nutella-framework/nutella_lib.js
src/run_net_bin.js
getFileExtension
function getFileExtension(file) { return file.name.substring(file.name.lastIndexOf('.')+1, file.name.length).toLowerCase() }
javascript
function getFileExtension(file) { return file.name.substring(file.name.lastIndexOf('.')+1, file.name.length).toLowerCase() }
[ "function", "getFileExtension", "(", "file", ")", "{", "return", "file", ".", "name", ".", "substring", "(", "file", ".", "name", ".", "lastIndexOf", "(", "'.'", ")", "+", "1", ",", "file", ".", "name", ".", "length", ")", ".", "toLowerCase", "(", ")", "}" ]
Helper function Extracts the extension from a file object
[ "Helper", "function", "Extracts", "the", "extension", "from", "a", "file", "object" ]
b3a3406a407e2a1ada6edcc503b70991f9cb249b
https://github.com/nutella-framework/nutella_lib.js/blob/b3a3406a407e2a1ada6edcc503b70991f9cb249b/src/run_net_bin.js#L57-L59
58,023
nutella-framework/nutella_lib.js
src/run_net_bin.js
isAlreadyUploaded
function isAlreadyUploaded(file_mngr_url, filename, file_exists_cb, file_absent_cb) { var req = new XMLHttpRequest(); req.open("GET", file_mngr_url + "/test/" + filename); req.onload = function(e) { var url = JSON.parse(req.response).url; if (url === undefined) file_absent_cb(); else file_exists_cb(url); }; req.send(); }
javascript
function isAlreadyUploaded(file_mngr_url, filename, file_exists_cb, file_absent_cb) { var req = new XMLHttpRequest(); req.open("GET", file_mngr_url + "/test/" + filename); req.onload = function(e) { var url = JSON.parse(req.response).url; if (url === undefined) file_absent_cb(); else file_exists_cb(url); }; req.send(); }
[ "function", "isAlreadyUploaded", "(", "file_mngr_url", ",", "filename", ",", "file_exists_cb", ",", "file_absent_cb", ")", "{", "var", "req", "=", "new", "XMLHttpRequest", "(", ")", ";", "req", ".", "open", "(", "\"GET\"", ",", "file_mngr_url", "+", "\"/test/\"", "+", "filename", ")", ";", "req", ".", "onload", "=", "function", "(", "e", ")", "{", "var", "url", "=", "JSON", ".", "parse", "(", "req", ".", "response", ")", ".", "url", ";", "if", "(", "url", "===", "undefined", ")", "file_absent_cb", "(", ")", ";", "else", "file_exists_cb", "(", "url", ")", ";", "}", ";", "req", ".", "send", "(", ")", ";", "}" ]
Helper function This function checks if a particular filename already exists. If so it executes the first callback that is passed, otherwise the second one
[ "Helper", "function", "This", "function", "checks", "if", "a", "particular", "filename", "already", "exists", ".", "If", "so", "it", "executes", "the", "first", "callback", "that", "is", "passed", "otherwise", "the", "second", "one" ]
b3a3406a407e2a1ada6edcc503b70991f9cb249b
https://github.com/nutella-framework/nutella_lib.js/blob/b3a3406a407e2a1ada6edcc503b70991f9cb249b/src/run_net_bin.js#L68-L79
58,024
nutella-framework/nutella_lib.js
src/run_net_bin.js
upload
function upload(file_mngr_url, file, filename, success, error) { // Assemble data var fd = new FormData(); fd.append("filename", filename); fd.append("file", file); var req = new XMLHttpRequest(); req.open("POST", file_mngr_url + "/upload"); req.onload = function(e) { var url = JSON.parse(req.response).url; if (url === undefined) error(); else success(url); }; req.send(fd); }
javascript
function upload(file_mngr_url, file, filename, success, error) { // Assemble data var fd = new FormData(); fd.append("filename", filename); fd.append("file", file); var req = new XMLHttpRequest(); req.open("POST", file_mngr_url + "/upload"); req.onload = function(e) { var url = JSON.parse(req.response).url; if (url === undefined) error(); else success(url); }; req.send(fd); }
[ "function", "upload", "(", "file_mngr_url", ",", "file", ",", "filename", ",", "success", ",", "error", ")", "{", "// Assemble data", "var", "fd", "=", "new", "FormData", "(", ")", ";", "fd", ".", "append", "(", "\"filename\"", ",", "filename", ")", ";", "fd", ".", "append", "(", "\"file\"", ",", "file", ")", ";", "var", "req", "=", "new", "XMLHttpRequest", "(", ")", ";", "req", ".", "open", "(", "\"POST\"", ",", "file_mngr_url", "+", "\"/upload\"", ")", ";", "req", ".", "onload", "=", "function", "(", "e", ")", "{", "var", "url", "=", "JSON", ".", "parse", "(", "req", ".", "response", ")", ".", "url", ";", "if", "(", "url", "===", "undefined", ")", "error", "(", ")", ";", "else", "success", "(", "url", ")", ";", "}", ";", "req", ".", "send", "(", "fd", ")", ";", "}" ]
Helper function This function uploads a file with a certain file name. If the upload is successful the first callback is executed, otherwise the second one is.
[ "Helper", "function", "This", "function", "uploads", "a", "file", "with", "a", "certain", "file", "name", ".", "If", "the", "upload", "is", "successful", "the", "first", "callback", "is", "executed", "otherwise", "the", "second", "one", "is", "." ]
b3a3406a407e2a1ada6edcc503b70991f9cb249b
https://github.com/nutella-framework/nutella_lib.js/blob/b3a3406a407e2a1ada6edcc503b70991f9cb249b/src/run_net_bin.js#L87-L102