attribute.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _namespace = require('./namespace');
  4. var _namespace2 = _interopRequireDefault(_namespace);
  5. var _types = require('./types');
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10. var Attribute = function (_Namespace) {
  11. _inherits(Attribute, _Namespace);
  12. function Attribute(opts) {
  13. _classCallCheck(this, Attribute);
  14. var _this = _possibleConstructorReturn(this, _Namespace.call(this, opts));
  15. _this.type = _types.ATTRIBUTE;
  16. _this.raws = {};
  17. return _this;
  18. }
  19. Attribute.prototype.toString = function toString() {
  20. var selector = [this.spaces.before, '[', this.ns, this.attribute];
  21. if (this.operator) {
  22. selector.push(this.operator);
  23. }
  24. if (this.value) {
  25. selector.push(this.value);
  26. }
  27. if (this.raws.insensitive) {
  28. selector.push(this.raws.insensitive);
  29. } else if (this.insensitive) {
  30. selector.push(' i');
  31. }
  32. selector.push(']');
  33. return selector.concat(this.spaces.after).join('');
  34. };
  35. return Attribute;
  36. }(_namespace2.default);
  37. exports.default = Attribute;
  38. module.exports = exports['default'];