Attributes.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. var __values = (this && this.__values) || function(o) {
  3. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  4. if (m) return m.call(o);
  5. if (o && typeof o.length === "number") return {
  6. next: function () {
  7. if (o && i >= o.length) o = void 0;
  8. return { value: o && o[i++], done: !o };
  9. }
  10. };
  11. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.Attributes = exports.INHERIT = void 0;
  15. exports.INHERIT = '_inherit_';
  16. var Attributes = (function () {
  17. function Attributes(defaults, global) {
  18. this.global = global;
  19. this.defaults = Object.create(global);
  20. this.inherited = Object.create(this.defaults);
  21. this.attributes = Object.create(this.inherited);
  22. Object.assign(this.defaults, defaults);
  23. }
  24. Attributes.prototype.set = function (name, value) {
  25. this.attributes[name] = value;
  26. };
  27. Attributes.prototype.setList = function (list) {
  28. Object.assign(this.attributes, list);
  29. };
  30. Attributes.prototype.get = function (name) {
  31. var value = this.attributes[name];
  32. if (value === exports.INHERIT) {
  33. value = this.global[name];
  34. }
  35. return value;
  36. };
  37. Attributes.prototype.getExplicit = function (name) {
  38. if (!this.attributes.hasOwnProperty(name)) {
  39. return undefined;
  40. }
  41. return this.attributes[name];
  42. };
  43. Attributes.prototype.getList = function () {
  44. var e_1, _a;
  45. var names = [];
  46. for (var _i = 0; _i < arguments.length; _i++) {
  47. names[_i] = arguments[_i];
  48. }
  49. var values = {};
  50. try {
  51. for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
  52. var name_1 = names_1_1.value;
  53. values[name_1] = this.get(name_1);
  54. }
  55. }
  56. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  57. finally {
  58. try {
  59. if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
  60. }
  61. finally { if (e_1) throw e_1.error; }
  62. }
  63. return values;
  64. };
  65. Attributes.prototype.setInherited = function (name, value) {
  66. this.inherited[name] = value;
  67. };
  68. Attributes.prototype.getInherited = function (name) {
  69. return this.inherited[name];
  70. };
  71. Attributes.prototype.getDefault = function (name) {
  72. return this.defaults[name];
  73. };
  74. Attributes.prototype.isSet = function (name) {
  75. return this.attributes.hasOwnProperty(name) || this.inherited.hasOwnProperty(name);
  76. };
  77. Attributes.prototype.hasDefault = function (name) {
  78. return (name in this.defaults);
  79. };
  80. Attributes.prototype.getExplicitNames = function () {
  81. return Object.keys(this.attributes);
  82. };
  83. Attributes.prototype.getInheritedNames = function () {
  84. return Object.keys(this.inherited);
  85. };
  86. Attributes.prototype.getDefaultNames = function () {
  87. return Object.keys(this.defaults);
  88. };
  89. Attributes.prototype.getGlobalNames = function () {
  90. return Object.keys(this.global);
  91. };
  92. Attributes.prototype.getAllAttributes = function () {
  93. return this.attributes;
  94. };
  95. Attributes.prototype.getAllInherited = function () {
  96. return this.inherited;
  97. };
  98. Attributes.prototype.getAllDefaults = function () {
  99. return this.defaults;
  100. };
  101. Attributes.prototype.getAllGlobals = function () {
  102. return this.global;
  103. };
  104. return Attributes;
  105. }());
  106. exports.Attributes = Attributes;
  107. //# sourceMappingURL=Attributes.js.map