soundtouch-api
Version:
SoundTouch API using TypeScript
91 lines • 2.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XMLElement = void 0;
var XMLElement = /** @class */ (function () {
function XMLElement(element) {
this.data = element;
}
XMLElement.prototype.getAttribute = function (name) {
if (!this.data.$) {
return undefined;
}
return this.data.$[name];
};
XMLElement.prototype.getText = function (field) {
if (field === undefined) {
return XMLElement.tryGetTextArray(this.data);
}
return XMLElement.tryGetTextArray(this.data[field]);
};
XMLElement.tryGetTextArray = function (arr) {
if (arr instanceof Array && arr.length > 0) {
return this.tryGetTextObject(arr[0]);
}
return XMLElement.tryGetTextObject(arr);
};
XMLElement.tryGetTextObject = function (obj) {
if (typeof obj === 'object') {
return obj._;
}
return XMLElement.tryGetTextString(obj);
};
XMLElement.tryGetTextString = function (str) {
if (typeof str === 'string') {
return str;
}
return undefined;
};
XMLElement.prototype.hasAttribute = function (attribute) {
if (!this.data.$) {
return false;
}
return this.data.$[attribute] !== undefined;
};
XMLElement.prototype.hasAttributes = function (attributes) {
if (!this.data.$) {
return false;
}
for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
var attr = attributes_1[_i];
if (this.data.$[attr] === undefined) {
return false;
}
}
return true;
};
XMLElement.prototype.hasChild = function (child) {
return typeof this.data[child] === 'object';
};
XMLElement.prototype.hasChildren = function (children) {
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
var child = children_1[_i];
if (typeof this.data[child] !== 'object') {
return false;
}
}
return true;
};
XMLElement.prototype.getChild = function (name) {
var value = this.data[name];
if (!value) {
return undefined;
}
if (value instanceof Array) {
if (value.length > 0) {
return new XMLElement(value[0]);
}
return undefined;
}
return new XMLElement(value);
};
XMLElement.prototype.getList = function (name) {
var value = this.data[name];
if (!(value instanceof Array)) {
return [];
}
return value.map(function (v) { return new XMLElement(v); });
};
return XMLElement;
}());
exports.XMLElement = XMLElement;
//# sourceMappingURL=xml-element.js.map