Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal] Replace var with let in ui/public/utils (no rison) #6951

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ui/public/utils/add_word_breaks.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
define(function () {
return function addWordBreaks(text, minLineLength) {
text = text || '';
var lineSize = 0;
var newText = '';
var inHtmlTag = false;
var inHtmlChar = false;
let lineSize = 0;
let newText = '';
let inHtmlTag = false;
let inHtmlChar = false;

for (var i = 0, len = text.length; i < len; i++) {
var chr = text.charAt(i);
for (let i = 0, len = text.length; i < len; i++) {
let chr = text.charAt(i);
newText += chr;

switch (chr) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/utils/brush_event.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import moment from 'moment';
export default function brushEventProvider(timefilter) {
return function (event) {
var from = moment(event.range[0]);
var to = moment(event.range[1]);
let from = moment(event.range[0]);
let to = moment(event.range[1]);

if (to - from === 0) return;

Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/utils/cidr_mask.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Ipv4Address from 'ui/utils/ipv4_address';
var NUM_BITS = 32;
let NUM_BITS = 32;

function throwError(mask) {
throw Error('Invalid CIDR mask: ' + mask);
}

function CidrMask(mask) {
var splits = mask.split('\/');
let splits = mask.split('\/');
if (splits.length !== 2) throwError(mask);
this.initialAddress = new Ipv4Address(splits[0]);
this.prefixLength = Number(splits[1]);
if (this.prefixLength < 1 || this.prefixLength > NUM_BITS) throwError(mask);
}

CidrMask.prototype.getRange = function () {
var variableBits = NUM_BITS - this.prefixLength;
var fromAddress = this.initialAddress.valueOf() >> variableBits << variableBits >>> 0; // >>> 0 coerces to unsigned
var numAddresses = Math.pow(2, variableBits);
let variableBits = NUM_BITS - this.prefixLength;
let fromAddress = this.initialAddress.valueOf() >> variableBits << variableBits >>> 0; // >>> 0 coerces to unsigned
let numAddresses = Math.pow(2, variableBits);
return {
from: new Ipv4Address(fromAddress).toString(),
to: new Ipv4Address(fromAddress + numAddresses - 1).toString()
Expand Down
18 changes: 9 additions & 9 deletions src/ui/public/utils/date_math.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import _ from 'lodash';
import moment from 'moment';

var units = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms'];
var unitsAsc = _.sortBy(units, function (unit) {
let units = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms'];
let unitsAsc = _.sortBy(units, function (unit) {
return moment.duration(1, unit).valueOf();
});
var unitsDesc = unitsAsc.reverse();
let unitsDesc = unitsAsc.reverse();

/* This is a simplified version of elasticsearch's date parser */
function parse(text, roundUp) {
Expand All @@ -14,7 +14,7 @@ function parse(text, roundUp) {
if (_.isDate(text)) return moment(text);

let time;
var mathString = '';
let mathString = '';
let index;
let parseString;

Expand Down Expand Up @@ -42,12 +42,12 @@ function parse(text, roundUp) {
}

function parseDateMath(mathString, time, roundUp) {
var dateTime = time;
var i = 0;
var len = mathString.length;
let dateTime = time;
let i = 0;
let len = mathString.length;

while (i < len) {
var c = mathString.charAt(i++);
let c = mathString.charAt(i++);
let type;
let num;
let unit;
Expand All @@ -67,7 +67,7 @@ function parseDateMath(mathString, time, roundUp) {
} else if (mathString.length === 2) {
num = mathString.charAt(i);
} else {
var numFrom = i;
let numFrom = i;
while (!isNaN(mathString.charAt(i))) {
i++;
if (i > 10) return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/utils/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
}
},
parse: function (rangeString, format) {
var chunks = rangeString.split(' to ');
let chunks = rangeString.split(' to ');
if (chunks.length === 2) return {from: moment(chunks[0], format), to: moment(chunks[1], format)};

chunks = rangeString.split('Before ');
Expand Down
24 changes: 12 additions & 12 deletions src/ui/public/utils/decode_geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
* @return {Object} interval
*/
function decodeGeoHash(geohash) {
var BITS = [16, 8, 4, 2, 1];
var BASE32 = '0123456789bcdefghjkmnpqrstuvwxyz';
var is_even = 1;
var lat = [];
var lon = [];
let BITS = [16, 8, 4, 2, 1];
let BASE32 = '0123456789bcdefghjkmnpqrstuvwxyz';
let is_even = 1;
let lat = [];
let lon = [];
lat[0] = -90.0;
lat[1] = 90.0;
lon[0] = -180.0;
lon[1] = 180.0;
var lat_err = 90.0;
var lon_err = 180.0;
for (var i = 0; i < geohash.length; i++) {
var c = geohash[i];
var cd = BASE32.indexOf(c);
for (var j = 0; j < 5; j++) {
var mask = BITS[j];
let lat_err = 90.0;
let lon_err = 180.0;
for (let i = 0; i < geohash.length; i++) {
let c = geohash[i];
let cd = BASE32.indexOf(c);
for (let j = 0; j < 5; j++) {
let mask = BITS[j];
if (is_even) {
lon_err /= 2;
refine_interval(lon, cd, mask);
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/utils/diff_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import angular from 'angular';

export default function (target, source) {

var diff = {};
let diff = {};

/**
* Filter the private vars
* @param {string} key The keys
* @returns {boolean}
*/
var filterPrivateAndMethods = function (obj) {
let filterPrivateAndMethods = function (obj) {
return function (key) {
if (_.isFunction(obj[key])) return false;
if (key.charAt(0) === '$') return false;
return key.charAt(0) !== '_';
};
};

var targetKeys = _.keys(target).filter(filterPrivateAndMethods(target));
var sourceKeys = _.keys(source).filter(filterPrivateAndMethods(source));
let targetKeys = _.keys(target).filter(filterPrivateAndMethods(target));
let sourceKeys = _.keys(source).filter(filterPrivateAndMethods(source));

// Find the keys to be removed
diff.removed = _.difference(targetKeys, sourceKeys);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/utils/diff_time_picker_vals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import angular from 'angular';
export default function DiffTimePickerValuesFn() {

var valueOf = function (o) {
let valueOf = function (o) {
if (o) return o.valueOf();
};

Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/utils/es_bool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function () {
var map = {
let map = {
'false': false,
'off': false,
'no': false,
Expand All @@ -11,7 +11,7 @@ define(function () {
};

return function (str) {
var bool = map[String(str)];
let bool = map[String(str)];

if (typeof bool !== 'boolean') {
throw new TypeError('"' + str + '" does not map to an esBool');
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/utils/find_by_param.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'lodash';
// if the param is missing, return undefined
export default function findByParam(values, param) {
if (_.isArray(values)) { // point series chart
var index = _.findIndex(values, param);
let index = _.findIndex(values, param);
if (index === -1) return;
return values[index][param];
}
Expand Down
16 changes: 8 additions & 8 deletions src/ui/public/utils/ipv4_address.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
define(function () {
var NUM_BYTES = 4;
var BYTE_SIZE = 256;
let NUM_BYTES = 4;
let BYTE_SIZE = 256;

function throwError(ipAddress) {
throw Error('Invalid IPv4 address: ' + ipAddress);
Expand All @@ -19,11 +19,11 @@ define(function () {
if (typeof ipAddress === 'string') {
this.value = 0;

var bytes = ipAddress.split('.');
let bytes = ipAddress.split('.');
if (bytes.length !== NUM_BYTES) throwError(ipAddress);

for (var i = 0; i < bytes.length; i++) {
var byte = Number(bytes[i]);
for (let i = 0; i < bytes.length; i++) {
let byte = Number(bytes[i]);
if (!isIntegerInRange(byte, 0, BYTE_SIZE)) throwError(ipAddress);
this.value += Math.pow(BYTE_SIZE, NUM_BYTES - 1 - i) * byte;
}
Expand All @@ -33,9 +33,9 @@ define(function () {
}

Ipv4Address.prototype.toString = function () {
var value = this.value;
var bytes = [];
for (var i = 0; i < NUM_BYTES; i++) {
let value = this.value;
let bytes = [];
for (let i = 0; i < NUM_BYTES; i++) {
bytes.unshift(value % 256);
value = Math.floor(value / 256);
}
Expand Down
14 changes: 7 additions & 7 deletions src/ui/public/utils/mapping_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import angular from 'angular';
import _ from 'lodash';
define(function () {
return function MappingSetupService(kbnIndex, es) {
var mappingSetup = this;
let mappingSetup = this;

var json = {
let json = {
_serialize: function (val) {
if (val != null) return angular.toJson(val);
},
Expand All @@ -16,14 +16,14 @@ define(function () {
/**
* Use to create the mappings, but that should only happen one at a time
*/
var activeTypeCreations = {};
let activeTypeCreations = {};

/**
* Get the list of type's mapped in elasticsearch
* @return {[type]} [description]
*/
var getKnownKibanaTypes = _.once(function () {
var indexName = kbnIndex;
let getKnownKibanaTypes = _.once(function () {
let indexName = kbnIndex;
return es.indices.getFieldMapping({
// only concerned with types in this kibana index
index: indexName,
Expand Down Expand Up @@ -70,13 +70,13 @@ define(function () {
});
}

var prom = getKnownKibanaTypes()
let prom = getKnownKibanaTypes()
.then(function (knownTypes) {
// if the type is in the knownTypes array already
if (~knownTypes.indexOf(type)) return false;

// we need to create the mapping
var body = {};
let body = {};
body[type] = {
properties: mapping
};
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/utils/no_white_space.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var TAGS_WITH_WS = />\s+</g;
let TAGS_WITH_WS = />\s+</g;

/**
* Remove all of the whitespace between html tags
Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/utils/obj_define.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ObjDefine(defaults, prototype) {
}

ObjDefine.REDEFINE_SUPPORTED = (function () {
var a = Object.create(Object.prototype, {
let a = Object.create(Object.prototype, {
prop: {
configurable: true,
value: 1
Expand Down Expand Up @@ -66,7 +66,7 @@ ObjDefine.prototype.comp = function (name, val) {
* @return {object} - created object
*/
ObjDefine.prototype.create = function () {
var self = this;
let self = this;
self.obj = Object.create(this.prototype, self.descs);

if (!ObjDefine.REDEFINE_SUPPORTED && !self.prototype.toJSON) {
Expand All @@ -76,7 +76,7 @@ ObjDefine.prototype.create = function () {
// due to https://github.com/ariya/phantomjs/issues/11856
self.obj.toJSON = function () {
return _.transform(self.obj, function (json, val, key) {
var desc = self.descs[key];
let desc = self.descs[key];
if (desc && desc.enumerable && val == null) return;
json[key] = val;
}, {});
Expand All @@ -97,8 +97,8 @@ ObjDefine.prototype._define = function (name, val, exported, changeable) {
};

ObjDefine.prototype._describe = function (name, val, exported, changeable) {
var self = this;
var exists = val != null;
let self = this;
let exists = val != null;

if (exported && ObjDefine.REDEFINE_SUPPORTED) {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/utils/ordinal_suffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export default function addOrdinalSuffix(num) {
};

function suffix(num) {
var int = Math.floor(parseFloat(num));
let int = Math.floor(parseFloat(num));

var hunth = int % 100;
let hunth = int % 100;
if (hunth >= 11 && hunth <= 13) return 'th';

var tenth = int % 10;
let tenth = int % 10;
if (tenth === 1) return 'st';
if (tenth === 2) return 'nd';
if (tenth === 3) return 'rd';
Expand Down
12 changes: 6 additions & 6 deletions src/ui/public/utils/parse_interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import moment from 'moment';
import dateMath from 'ui/utils/date_math';

// Assume interval is in the form (value)(unit), such as "1h"
var INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + dateMath.units.join('|') + ')$');
let INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + dateMath.units.join('|') + ')$');

export default function parseInterval(interval) {
var matches = String(interval).trim().match(INTERVAL_STRING_RE);
let matches = String(interval).trim().match(INTERVAL_STRING_RE);

if (!matches) return null;

try {
var value = parseFloat(matches[1]) || 1;
var unit = matches[2];
let value = parseFloat(matches[1]) || 1;
let unit = matches[2];

var duration = moment.duration(value, unit);
let duration = moment.duration(value, unit);

// There is an error with moment, where if you have a fractional interval between 0 and 1, then when you add that
// interval to an existing moment object, it will remain unchanged, which causes problems in the ordered_x_keys
Expand All @@ -23,7 +23,7 @@ export default function parseInterval(interval) {
// adding 0.5 days until we hit the end date. However, since there is a bug in moment, when you add 0.5 days to
// the start date, you get the same exact date (instead of being ahead by 12 hours). So instead of returning
// a duration corresponding to 0.5 hours, we return a duration corresponding to 12 hours.
var selectedUnit = _.find(dateMath.units, function (unit) {
let selectedUnit = _.find(dateMath.units, function (unit) {
return Math.abs(duration.as(unit)) >= 1;
});

Expand Down
Loading