From 6f50866d0f8c4434866aa0c18fb2443df9e804b1 Mon Sep 17 00:00:00 2001 From: Markus Stefanko Date: Thu, 8 Mar 2018 13:22:13 +0700 Subject: [PATCH] Fix formatting --- index.js | 295 +++++++++++++++++++++++++++---------------------------- 1 file changed, 146 insertions(+), 149 deletions(-) diff --git a/index.js b/index.js index 4b3b905..e99a6a5 100644 --- a/index.js +++ b/index.js @@ -528,182 +528,179 @@ var SpreadsheetRow = function( spreadsheet, data, xml ){ } function SpreadsheetCell(spreadsheet, ss_key, worksheet_id, data){ - var links; - this.row = parseInt(data['gs:cell']['$']['row']); - this.col = parseInt(data['gs:cell']['$']['col']); - this.batchId = 'R'+this.row+'C'+this.col; - if(data['id'] == "https://spreadsheets.google.com/feeds/cells/" + ss_key + "/" + worksheet_id + '/' + this.batchId) { - this.ws_id = worksheet_id; - this.ss = ss_key; - }else{ - this.id = data['id']; - } + var links; + this.row = parseInt(data['gs:cell']['$']['row']); + this.col = parseInt(data['gs:cell']['$']['col']); + this.batchId = 'R'+this.row+'C'+this.col; + if(data['id'] == "https://spreadsheets.google.com/feeds/cells/" + ss_key + "/" + worksheet_id + '/' + this.batchId) { + this.ws_id = worksheet_id; + this.ss = ss_key; + }else{ + this.id = data['id']; + } - this['_links'] = []; - links = forceArray( data.link ); - for (var i = 0; i < links.length; i++) { - link = links[i]; - if(link['$']['rel'] == "self" && link['$']['href'] == this.getSelf()) continue; - if(link['$']['rel'] == "edit" && link['$']['href'] == this.getEdit()) continue; - this['_links'][ link['$']['rel'] ] = link['$']['href']; - }; - if(this['_links'].length == 0) delete this['_links']; + this['_links'] = []; + links = forceArray( data.link ); + for (var i = 0; i < links.length; i++) { + link = links[i]; + if(link['$']['rel'] == "self" && link['$']['href'] == this.getSelf()) continue; + if(link['$']['rel'] == "edit" && link['$']['href'] == this.getEdit()) continue; + this['_links'][ link['$']['rel'] ] = link['$']['href']; + }; + if(this['_links'].length == 0) delete this['_links']; - this.updateValuesFromResponseData(data); + this.updateValuesFromResponseData(data); - return this; + return this; }; - SpreadsheetCell.prototype.getId = function() { - if(!!this.id) { - return this.id; - } else { - return "https://spreadsheets.google.com/feeds/cells/" + this.ss + "/" + this.ws_id + '/' + this.batchId; - } - } - - SpreadsheetCell.prototype.getEdit = function() { - if(!!this['_links'] && !!this['_links']['edit']) { - return this['_links']['edit']; - } else { - return this.getId().replace(this.batchId, "private/full/" + this.batchId); - } - } +SpreadsheetCell.prototype.getId = function() { + if(!!this.id) { + return this.id; + } else { + return "https://spreadsheets.google.com/feeds/cells/" + this.ss + "/" + this.ws_id + '/' + this.batchId; + } +} - SpreadsheetCell.prototype.getSelf = function() { - if(!!this['_links'] && !!this['_links']['edit']) { - return this['_links']['edit']; - } else { - return this.getId().replace(this.batchId, "private/full/" + this.batchId); - } - } +SpreadsheetCell.prototype.getEdit = function() { + if(!!this['_links'] && !!this['_links']['edit']) { + return this['_links']['edit']; + } else { + return this.getId().replace(this.batchId, "private/full/" + this.batchId); + } +} - SpreadsheetCell.prototype.updateValuesFromResponseData = function(_data) { - // formula value - var input_val = _data['gs:cell']['$']['inputValue']; - // inputValue can be undefined so substr throws an error - // still unsure how this situation happens - if (input_val && input_val.substr(0,1) === '='){ - this._formula = input_val; - } else { - this._formula = undefined; - } +SpreadsheetCell.prototype.getSelf = function() { + if(!!this['_links'] && !!this['_links']['edit']) { + return this['_links']['edit']; + } else { + return this.getId().replace(this.batchId, "private/full/" + this.batchId); + } +} - // numeric values - if (_data['gs:cell']['$']['numericValue'] !== undefined) { - this._numericValue = parseFloat(_data['gs:cell']['$']['numericValue']); - } else { - this._numericValue = undefined; - } +SpreadsheetCell.prototype.updateValuesFromResponseData = function(_data) { + // formula value + var input_val = _data['gs:cell']['$']['inputValue']; + // inputValue can be undefined so substr throws an error + // still unsure how this situation happens + if (input_val && input_val.substr(0,1) === '='){ + this._formula = input_val; + } else { + this._formula = undefined; + } - // the main "value" - its always a string - this._value = _data['gs:cell']['_'] || ''; - } + // numeric values + if (_data['gs:cell']['$']['numericValue'] !== undefined) { + this._numericValue = parseFloat(_data['gs:cell']['$']['numericValue']); + } else { + this._numericValue = undefined; + } - SpreadsheetCell.prototype.setValue = function(new_value, cb) { - this.value = new_value; - this.save(cb); - }; + // the main "value" - its always a string + this._value = _data['gs:cell']['_'] || ''; +} - SpreadsheetCell.prototype._clearValue = function() { - this._formula = undefined; - this._numericValue = undefined; - this._value = ''; - } +SpreadsheetCell.prototype.setValue = function(new_value, cb) { + this.value = new_value; + this.save(cb); +}; - Object.defineProperty(SpreadsheetCell.prototype, "value", { - get: function(){ - return this._value; - }, - set: function(val){ - if (!val) return this._clearValue(); - - var numeric_val = parseFloat(val); - if (!isNaN(numeric_val)){ - this._numericValue = numeric_val; - this._value = val.toString(); - } else { - this._numericValue = undefined; - this._value = val; - } - - if (typeof val == 'string' && val.substr(0,1) === '=') { - // use the getter to clear the value - this.formula = val; - } else { - this._formula = undefined; - } - } - }); +SpreadsheetCell.prototype._clearValue = function() { + this._formula = undefined; + this._numericValue = undefined; + this._value = ''; +} - Object.defineProperty(SpreadsheetCell.prototype, "formula", { - get: function() { - return this._formula; - }, - set: function(val){ - if (!val) return this._clearValue(); - - if (val.substr(0,1) !== '=') { - throw new Error('Formulas must start with "="'); - } - this._numericValue = undefined; - this._value = '*SAVE TO GET NEW VALUE*'; - this._formula = val; - } - }); +Object.defineProperty(SpreadsheetCell.prototype, "value", { + get: function(){ + return this._value; + }, + set: function(val){ + if (!val) return this._clearValue(); + + var numeric_val = parseFloat(val); + if (!isNaN(numeric_val)){ + this._numericValue = numeric_val; + this._value = val.toString(); + } else { + this._numericValue = undefined; + this._value = val; + } - Object.defineProperty(SpreadsheetCell.prototype, "numericValue", { - get: function() { - return this._numericValue; - }, - set: function(val) { - if (val === undefined || val === null) return this._clearValue(); + if (typeof val == 'string' && val.substr(0,1) === '=') { + // use the getter to clear the value + this.formula = val; + } else { + this._formula = undefined; + } + } +}); - if (isNaN(parseFloat(val)) || !isFinite(val)) { - throw new Error('Invalid numeric value assignment'); - } +Object.defineProperty(SpreadsheetCell.prototype, "formula", { + get: function() { + return this._formula; + }, + set: function(val){ + if (!val) return this._clearValue(); - this._value = val.toString(); - this._numericValue = parseFloat(val); - this._formula = undefined; - } - }); + if (val.substr(0,1) !== '=') { + throw new Error('Formulas must start with "="'); + } + this._numericValue = undefined; + this._value = '*SAVE TO GET NEW VALUE*'; + this._formula = val; + } +}); - Object.defineProperty(SpreadsheetCell.prototype, "valueForSave", { - get: function() { - return xmlSafeValue(this._formula || this._value); - } - }); +Object.defineProperty(SpreadsheetCell.prototype, "numericValue", { + get: function() { + return this._numericValue; + }, + set: function(val) { + if (val === undefined || val === null) return this._clearValue(); - SpreadsheetCell.prototype.save = function(cb) { - if ( !cb ) cb = function(){}; - this._needsSave = false; + if (isNaN(parseFloat(val)) || !isFinite(val)) { + throw new Error('Invalid numeric value assignment'); + } - var edit_id = 'https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full/R'+this.row+'C'+this.col; - var data_xml = - ''+this.getId()+''+ - ''+ - '' + this._value = val.toString(); + this._numericValue = parseFloat(val); + this._formula = undefined; + } +}); - data_xml = data_xml.replace('', ""); +Object.defineProperty(SpreadsheetCell.prototype, "valueForSave", { + get: function() { + return xmlSafeValue(this._formula || this._value); + } +}); - var self = this; +SpreadsheetCell.prototype.save = function(cb) { + if ( !cb ) cb = function(){}; + this._needsSave = false; - spreadsheet.makeFeedRequest( this.getEdit(), 'PUT', data_xml, function(err, response) { - if (err) return cb(err); - self.updateValuesFromResponseData(response); - cb(); - }); - } + var edit_id = 'https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full/R'+this.row+'C'+this.col; + var data_xml = + ''+this.getId()+''+ + ''+ + '' - SpreadsheetCell.prototype.del = function(cb) { - this.setValue('', cb); - } + data_xml = data_xml.replace('', ""); + var self = this; -GoogleSpreadsheet.SpreadsheetCell = SpreadsheetCell; + spreadsheet.makeFeedRequest( this.getEdit(), 'PUT', data_xml, function(err, response) { + if (err) return cb(err); + self.updateValuesFromResponseData(response); + cb(); + }); +} +SpreadsheetCell.prototype.del = function(cb) { + this.setValue('', cb); +} +GoogleSpreadsheet.SpreadsheetCell = SpreadsheetCell; module.exports = GoogleSpreadsheet;