Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 12f490a

Browse files
committed
Run prettier
1 parent 9cf0d16 commit 12f490a

22 files changed

+1480
-1336
lines changed

lib/analytics.js

Lines changed: 148 additions & 111 deletions
Large diffs are not rendered by default.

lib/cookie.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
'use strict';
1+
"use strict";
22

33
/**
44
* Module dependencies.
55
*/
66

7-
var bindAll = require('bind-all');
8-
var clone = require('@ndhoule/clone');
9-
var cookie = require('component-cookie');
10-
var debug = require('debug')('analytics.js:cookie');
11-
var defaults = require('@ndhoule/defaults');
12-
var json = require('json3');
13-
var topDomain = require('@segment/top-domain');
7+
var bindAll = require("bind-all");
8+
var clone = require("@ndhoule/clone");
9+
var cookie = require("component-cookie");
10+
var debug = require("debug")("analytics.js:cookie");
11+
var defaults = require("@ndhoule/defaults");
12+
var json = require("json3");
13+
var topDomain = require("@segment/top-domain");
1414

1515
/**
1616
* Initialize a new `Cookie` with `options`.
@@ -22,7 +22,6 @@ function Cookie(options) {
2222
this.options(options);
2323
}
2424

25-
2625
/**
2726
* Get or set the cookie options.
2827
*
@@ -38,13 +37,13 @@ Cookie.prototype.options = function(options) {
3837

3938
options = options || {};
4039

41-
var domain = '.' + topDomain(window.location.href);
42-
if (domain === '.') domain = null;
40+
var domain = "." + topDomain(window.location.href);
41+
if (domain === ".") domain = null;
4342

4443
this._options = defaults(options, {
4544
// default to a year
4645
maxage: 31536000000,
47-
path: '/',
46+
path: "/",
4847
domain: domain
4948
});
5049

@@ -55,15 +54,14 @@ Cookie.prototype.options = function(options) {
5554
// if the cookie isn't set, it probably means
5655
// that the domain is on the public suffix list
5756
// like myapp.herokuapp.com or localhost / ip.
58-
this.set('ajs:test', true);
59-
if (!this.get('ajs:test')) {
60-
debug('fallback to domain=null');
57+
this.set("ajs:test", true);
58+
if (!this.get("ajs:test")) {
59+
debug("fallback to domain=null");
6160
this._options.domain = null;
6261
}
63-
this.remove('ajs:test');
62+
this.remove("ajs:test");
6463
};
6564

66-
6765
/**
6866
* Set a `key` and `value` in our cookie.
6967
*
@@ -82,7 +80,6 @@ Cookie.prototype.set = function(key, value) {
8280
}
8381
};
8482

85-
8683
/**
8784
* Get a value from our cookie by `key`.
8885
*
@@ -100,7 +97,6 @@ Cookie.prototype.get = function(key) {
10097
}
10198
};
10299

103-
104100
/**
105101
* Remove a value from our cookie by `key`.
106102
*
@@ -117,14 +113,12 @@ Cookie.prototype.remove = function(key) {
117113
}
118114
};
119115

120-
121116
/**
122117
* Expose the cookie singleton.
123118
*/
124119

125120
module.exports = bindAll(new Cookie());
126121

127-
128122
/**
129123
* Expose the `Cookie` constructor.
130124
*/

lib/entity.js

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
'use strict';
1+
"use strict";
22

33
/*
44
* Module dependencies.
55
*/
66

7-
var clone = require('@ndhoule/clone');
8-
var cookie = require('./cookie');
9-
var debug = require('debug')('analytics:entity');
10-
var defaults = require('@ndhoule/defaults');
11-
var extend = require('@ndhoule/extend');
12-
var memory = require('./memory');
13-
var store = require('./store');
14-
var isodateTraverse = require('@segment/isodate-traverse');
7+
var clone = require("@ndhoule/clone");
8+
var cookie = require("./cookie");
9+
var debug = require("debug")("analytics:entity");
10+
var defaults = require("@ndhoule/defaults");
11+
var extend = require("@ndhoule/extend");
12+
var memory = require("./memory");
13+
var store = require("./store");
14+
var isodateTraverse = require("@segment/isodate-traverse");
1515

1616
/**
1717
* Expose `Entity`
1818
*/
1919

2020
module.exports = Entity;
2121

22-
2322
/**
2423
* Initialize new `Entity` with `options`.
2524
*
@@ -39,11 +38,11 @@ function Entity(options) {
3938
*/
4039

4140
Entity.prototype.initialize = function() {
42-
cookie.set('ajs:cookies', true);
41+
cookie.set("ajs:cookies", true);
4342

4443
// cookies are enabled.
45-
if (cookie.get('ajs:cookies')) {
46-
cookie.remove('ajs:cookies');
44+
if (cookie.get("ajs:cookies")) {
45+
cookie.remove("ajs:cookies");
4746
this._storage = cookie;
4847
return;
4948
}
@@ -55,7 +54,9 @@ Entity.prototype.initialize = function() {
5554
}
5655

5756
// fallback to memory storage.
58-
debug('warning using memory store both cookies and localStorage are disabled');
57+
debug(
58+
"warning using memory store both cookies and localStorage are disabled"
59+
);
5960
this._storage = memory;
6061
};
6162

@@ -67,7 +68,6 @@ Entity.prototype.storage = function() {
6768
return this._storage;
6869
};
6970

70-
7171
/**
7272
* Get or set storage `options`.
7373
*
@@ -82,7 +82,6 @@ Entity.prototype.options = function(options) {
8282
this._options = defaults(options || {}, this.defaults || {});
8383
};
8484

85-
8685
/**
8786
* Get or set the entity's `id`.
8887
*
@@ -91,14 +90,15 @@ Entity.prototype.options = function(options) {
9190

9291
Entity.prototype.id = function(id) {
9392
switch (arguments.length) {
94-
case 0: return this._getId();
95-
case 1: return this._setId(id);
96-
default:
97-
// No default case
93+
case 0:
94+
return this._getId();
95+
case 1:
96+
return this._setId(id);
97+
default:
98+
// No default case
9899
}
99100
};
100101

101-
102102
/**
103103
* Get the entity's id.
104104
*
@@ -112,7 +112,6 @@ Entity.prototype._getId = function() {
112112
return ret === undefined ? null : ret;
113113
};
114114

115-
116115
/**
117116
* Set the entity's `id`.
118117
*
@@ -127,7 +126,6 @@ Entity.prototype._setId = function(id) {
127126
}
128127
};
129128

130-
131129
/**
132130
* Get or set the entity's `traits`.
133131
*
@@ -138,14 +136,15 @@ Entity.prototype._setId = function(id) {
138136

139137
Entity.prototype.properties = Entity.prototype.traits = function(traits) {
140138
switch (arguments.length) {
141-
case 0: return this._getTraits();
142-
case 1: return this._setTraits(traits);
143-
default:
144-
// No default case
139+
case 0:
140+
return this._getTraits();
141+
case 1:
142+
return this._setTraits(traits);
143+
default:
144+
// No default case
145145
}
146146
};
147147

148-
149148
/**
150149
* Get the entity's traits. Always convert ISO date strings into real dates,
151150
* since they aren't parsed back from local storage.
@@ -154,11 +153,12 @@ Entity.prototype.properties = Entity.prototype.traits = function(traits) {
154153
*/
155154

156155
Entity.prototype._getTraits = function() {
157-
var ret = this._options.persist ? store.get(this._options.localStorage.key) : this._traits;
156+
var ret = this._options.persist
157+
? store.get(this._options.localStorage.key)
158+
: this._traits;
158159
return ret ? isodateTraverse(clone(ret)) : {};
159160
};
160161

161-
162162
/**
163163
* Set the entity's `traits`.
164164
*
@@ -174,7 +174,6 @@ Entity.prototype._setTraits = function(traits) {
174174
}
175175
};
176176

177-
178177
/**
179178
* Identify the entity with an `id` and `traits`. If we it's the same entity,
180179
* extend the existing `traits` instead of overwriting.
@@ -186,14 +185,14 @@ Entity.prototype._setTraits = function(traits) {
186185
Entity.prototype.identify = function(id, traits) {
187186
traits = traits || {};
188187
var current = this.id();
189-
if (current === null || current === id) traits = extend(this.traits(), traits);
188+
if (current === null || current === id)
189+
traits = extend(this.traits(), traits);
190190
if (id) this.id(id);
191-
this.debug('identify %o, %o', id, traits);
191+
this.debug("identify %o, %o", id, traits);
192192
this.traits(traits);
193193
this.save();
194194
};
195195

196-
197196
/**
198197
* Save the entity to local storage and the cookie.
199198
*
@@ -207,7 +206,6 @@ Entity.prototype.save = function() {
207206
return true;
208207
};
209208

210-
211209
/**
212210
* Log the entity out, reseting `id` and `traits` to defaults.
213211
*/
@@ -219,7 +217,6 @@ Entity.prototype.logout = function() {
219217
store.remove(this._options.localStorage.key);
220218
};
221219

222-
223220
/**
224221
* Reset all entity state, logging out and returning options to defaults.
225222
*/
@@ -229,7 +226,6 @@ Entity.prototype.reset = function() {
229226
this.options({});
230227
};
231228

232-
233229
/**
234230
* Load saved entity `id` or `traits` from storage.
235231
*/
@@ -238,4 +234,3 @@ Entity.prototype.load = function() {
238234
this.id(cookie.get(this._options.cookie.key));
239235
this.traits(store.get(this._options.localStorage.key));
240236
};
241-

lib/group.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
'use strict';
1+
"use strict";
22

33
/*
44
* Module dependencies.
55
*/
66

7-
var Entity = require('./entity');
8-
var bindAll = require('bind-all');
9-
var debug = require('debug')('analytics:group');
10-
var inherit = require('inherits');
7+
var Entity = require("./entity");
8+
var bindAll = require("bind-all");
9+
var debug = require("debug")("analytics:group");
10+
var inherit = require("inherits");
1111

1212
/**
1313
* Group defaults
@@ -16,14 +16,13 @@ var inherit = require('inherits');
1616
Group.defaults = {
1717
persist: true,
1818
cookie: {
19-
key: 'ajs_group_id'
19+
key: "ajs_group_id"
2020
},
2121
localStorage: {
22-
key: 'ajs_group_properties'
22+
key: "ajs_group_properties"
2323
}
2424
};
2525

26-
2726
/**
2827
* Initialize a new `Group` with `options`.
2928
*
@@ -36,21 +35,18 @@ function Group(options) {
3635
Entity.call(this, options);
3736
}
3837

39-
4038
/**
4139
* Inherit `Entity`
4240
*/
4341

4442
inherit(Group, Entity);
4543

46-
4744
/**
4845
* Expose the group singleton.
4946
*/
5047

5148
module.exports = bindAll(new Group());
5249

53-
5450
/**
5551
* Expose the `Group` constructor.
5652
*/

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
1+
"use strict";
22

33
/**
44
* Analytics.js
55
*
66
* (C) 2013-2016 Segment.io Inc.
77
*/
88

9-
var Analytics = require('./analytics');
9+
var Analytics = require("./analytics");
1010

1111
// Create a new `analytics` singleton.
1212
var analytics = new Analytics();
@@ -16,7 +16,7 @@ var analytics = new Analytics();
1616
analytics.require = require;
1717

1818
// Expose package version.
19-
analytics.VERSION = require('../package.json').version;
19+
analytics.VERSION = require("../package.json").version;
2020

2121
/*
2222
* Exports.

0 commit comments

Comments
 (0)