Skip to content

Commit 2c70d87

Browse files
committed
Moved identifiers into payload
1 parent 50c9dcb commit 2c70d87

7 files changed

Lines changed: 49 additions & 105 deletions

File tree

src/js/lib/detectors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
var
3838
lodash = require('./lodash'),
39-
identifiers = require('./identifiers'),
4039
helpers = require('./helpers'),
4140
murmurhash3_32_gc = require('murmurhash').v3,
4241
tz = require('jstimezonedetect').jstz.determine(),

src/js/lib/identifiers.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/js/payload.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
var
3838
lodash = require('./lib/lodash'),
39-
identifiers = require('./lib/identifiers'),
4039
json2 = require('JSON'),
4140
Base64 = require('Base64'),
4241
base64encode = Base64.btoa,
@@ -72,6 +71,28 @@
7271
return Math.floor(date / 86400000);
7372
}
7473

74+
/*
75+
* Is property a JSON?
76+
*/
77+
object.isJson = function (property) {
78+
return (!lodash.isUndefined(property) && !lodash.isNull(property) && property.constructor === {}.constructor);
79+
}
80+
81+
/*
82+
* Is property a non-empty JSON?
83+
*/
84+
object.isNonEmptyJson = function (property) {
85+
if (!object.isJson(property)) {
86+
return false;
87+
}
88+
for (var key in property) {
89+
if (property.hasOwnProperty(key)) {
90+
return true;
91+
}
92+
}
93+
return false;
94+
}
95+
7596
/**
7697
* A helper to build a Snowplow request string from an
7798
* an optional initial value plus a set of individual
@@ -142,7 +163,7 @@
142163
}
143164

144165
// ... for JSON objects
145-
if (identifiers.isJson(value)) {
166+
if (object.isJson(value)) {
146167
value = recurse(value);
147168
}
148169

@@ -166,7 +187,7 @@
166187

167188
var addJson = function (keyIfEncoded, keyIfNotEncoded, json) {
168189

169-
if (identifiers.isNonEmptyJson(json)) {
190+
if (object.isNonEmptyJson(json)) {
170191
var typed = appendTypes(json);
171192
var str = json2.stringify(typed);
172193

src/js/snowplow.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575

7676
// Load all our modules (at least until we fully modularize & remove grunt-concat)
7777
var
78-
identifiers = require('./lib/identifiers'),
7978
tracker = require('./tracker'),
8079
helpers = require('./lib/helpers'),
8180
queue = require('./queue'),

tests/identifiersT.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/intern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define({
22

33
// Non-functional test suites
4-
suites: ['tests/queueT', 'tests/payloadT', 'tests/identifiersT'],
4+
suites: ['tests/queueT', 'tests/payloadT'],
55

66
});

tests/payloadT.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ define([
2424

2525
name: 'Payload test',
2626

27+
'Identify JSON': function() {
28+
var json = {
29+
'name': 'john',
30+
'properties': {
31+
'age': 30,
32+
'languages': ['English', 'French']
33+
}
34+
};
35+
36+
assert.strictEqual(payload.isJson(json), true, 'JSON should be identified');
37+
},
38+
39+
'Identify non-JSON': function() {
40+
var nonJson = [1,2,3];
41+
42+
assert.strictEqual(payload.isJson(nonJson), false, 'non-JSON should be rejected');
43+
},
44+
45+
'Identify empty JSON': function() {
46+
var emptyJson = {};
47+
48+
assert.strictEqual(payload.isNonEmptyJson(emptyJson), false, 'identify {} as empty')
49+
},
50+
2751
'build payload': function () {
2852

2953
var sb = payload.payloadBuilder(false);

0 commit comments

Comments
 (0)