Comparing version 0.7.2 to 0.8.0
{ | ||
"name": "sajari", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"description": "JavaScript SDK for access to the Sajari search API", | ||
@@ -5,0 +5,0 @@ "author": { |
var isArray = require('./utils/isArray'); | ||
var urlutils = require('./utils/url'); | ||
/** | ||
@@ -83,9 +83,7 @@ * Query constructor | ||
for (i = 0; i < this.options[k].length; i++) { | ||
var val = ""; | ||
if (isArray(this.options[k][i].value)) { | ||
val = this.options[k][i].value.join(';'); | ||
} else if (typeof this.options[k][i].value === 'object') { | ||
val = JSON.stringify(this.options[k][i].value); | ||
} else { | ||
val = this.options[k][i].value | ||
var val = this.options[k][i].value; | ||
if (isArray(val)) { | ||
val = val.join(';'); | ||
} else if (typeof val === 'object') { | ||
val = JSON.stringify(val); | ||
} | ||
@@ -312,2 +310,21 @@ args[k + '[' + this.options[k][i].key + ']'] = val; | ||
return this; | ||
}, | ||
/** | ||
* Add multiple custom attributes via a "data" object | ||
*/ | ||
attrs: function(data) { | ||
if (typeof data == 'string') { | ||
data = urlutils.decodeUriArgs(data); | ||
} | ||
if (this.options.attrs === undefined) { | ||
this.options.attrs = []; | ||
} | ||
for (var k in data) { | ||
this.options.attrs.push({ | ||
key: k, | ||
value: data[k] | ||
}); | ||
} | ||
return this; | ||
} | ||
@@ -314,0 +331,0 @@ }; |
@@ -78,2 +78,24 @@ | ||
var query3 = api.query(); | ||
query3.attrs({ | ||
disco: 'dancer', | ||
yogi: 'bear' | ||
}); | ||
test('Query encoding 3', function (t) { | ||
var enc = query3.encode(); | ||
t.equal(enc.disco, "dancer"); | ||
t.equal(enc.yogi, "bear"); | ||
t.end(); | ||
}); | ||
var query4 = api.query(); | ||
query4.attrs('disco=dancer&yogi=bear'); | ||
test('Query encoding 4', function (t) { | ||
var enc = query4.encode(); | ||
t.equal(enc.disco, "dancer"); | ||
t.equal(enc.yogi, "bear"); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37414
1061