UNPKG

@iotile/iotile-cloud

Version:

A typescript library for interfacing with the IOTile Cloud API

54 lines 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ApiFilter = /** @class */ (function () { function ApiFilter() { this.filters = []; } ApiFilter.prototype.filterString = function () { // Build a '?name1=val1&name2=val2' string if (this.filters.length) { var dataFilter = '?' + this.filters.join('&'); return dataFilter; } return ''; }; ApiFilter.prototype.addFilter = function (name, value, unique) { if (unique === void 0) { unique = false; } var arg = name + '=' + value; if (unique) { this.removeFilter(name); } this.filters.push(arg); }; ApiFilter.prototype.removeFilter = function (name) { var arg = name + '='; this.filters = this.filters.filter(function (item) { return item.indexOf(arg) !== 0; }); }; // nb: if there are duplicate values for a key, returns the first ApiFilter.prototype.getFilter = function (name) { var value; for (var _i = 0, _a = this.filters; _i < _a.length; _i++) { var filter = _a[_i]; var _b = filter.split('='), key = _b[0], val = _b[1]; if (key == name) { value = val; break; } } return value; }; ApiFilter.prototype.copy = function () { var copy = new ApiFilter(); for (var _i = 0, _a = this.filters; _i < _a.length; _i++) { var filter = _a[_i]; var _b = filter.split('='), key = _b[0], val = _b[1]; copy.addFilter(key, val); } return copy; }; return ApiFilter; }()); exports.ApiFilter = ApiFilter; //# sourceMappingURL=apifilter.js.map