UNPKG

changelog-guru

Version:
130 lines (129 loc) 5.97 kB
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _Section_emoji, _Section_entities, _Section_order, _Section_position; import Commit from './Commit.js'; import Entity, { Compare } from './Entity.js'; import Message from './Message.js'; export var SectionPosition; (function (SectionPosition) { SectionPosition[SectionPosition["None"] = 0] = "None"; SectionPosition[SectionPosition["Subsection"] = 1] = "Subsection"; SectionPosition[SectionPosition["Details"] = 2] = "Details"; SectionPosition[SectionPosition["Group"] = 3] = "Group"; SectionPosition[SectionPosition["Footer"] = 4] = "Footer"; SectionPosition[SectionPosition["Body"] = 5] = "Body"; SectionPosition[SectionPosition["Header"] = 6] = "Header"; })(SectionPosition || (SectionPosition = {})); export var SectionOrder; (function (SectionOrder) { SectionOrder[SectionOrder["Default"] = 0] = "Default"; SectionOrder[SectionOrder["Max"] = Number.MAX_SAFE_INTEGER] = "Max"; SectionOrder[SectionOrder["Min"] = Number.MIN_SAFE_INTEGER] = "Min"; })(SectionOrder || (SectionOrder = {})); class Section extends Entity { constructor({ name, position, order, emoji }) { super(name); _Section_emoji.set(this, void 0); _Section_entities.set(this, new Map()); _Section_order.set(this, void 0); _Section_position.set(this, void 0); __classPrivateFieldSet(this, _Section_order, order ?? SectionOrder.Default, "f"); __classPrivateFieldSet(this, _Section_emoji, emoji, "f"); __classPrivateFieldSet(this, _Section_position, position ?? SectionPosition.None, "f"); } static compare(a, b) { let result = b.position - a.position || a.order - b.order || super.compare(a, b); if (result === Compare.Equal) result = a.name.localeCompare(b.name); return Math.min(Math.max(result, Compare.Less), Compare.More); } get title() { return __classPrivateFieldGet(this, _Section_emoji, "f") ? `${__classPrivateFieldGet(this, _Section_emoji, "f")} ${this.name}` : this.name; } get sections() { return this.listOf(Section); } get commits() { return this.listOf(Commit); } get messages() { return this.listOf(Message); } get priority() { let priority = super.priority; if (__classPrivateFieldGet(this, _Section_entities, "f").size) { [this.sections, this.messages, this.commits].forEach((entities) => { priority = entities.reduce((acc, entity) => acc + entity.priority, priority); }); } return priority; } get position() { return __classPrivateFieldGet(this, _Section_position, "f"); } set position(position) { __classPrivateFieldSet(this, _Section_position, position, "f"); } get order() { return __classPrivateFieldGet(this, _Section_order, "f"); } set order(order) { __classPrivateFieldSet(this, _Section_order, order, "f"); } get isSubsection() { return this.position === SectionPosition.Subsection; } get isDetails() { return this.position === SectionPosition.Details; } get isGroup() { return this.position === SectionPosition.Group; } get isEmpty() { return !__classPrivateFieldGet(this, _Section_entities, "f").size; } add(entity) { if (!__classPrivateFieldGet(this, _Section_entities, "f").has(entity.name)) { __classPrivateFieldGet(this, _Section_entities, "f").set(entity.name, entity); if (entity instanceof Section && !entity.isDetails) entity.position = SectionPosition.Subsection; } } assign(relations, type) { const { commits } = this; if (type) { if (commits.length) { let parent = commits[0] ? relations.get(commits[0].name) : undefined; if (parent) parent.add(this); commits.forEach(commit => { parent = relations.get(commit.name); if (parent) parent.remove(commit); relations.set(commit.name, this); }); } } else { commits.forEach(commit => (relations.has(commit.name) ? this.remove(commit) : relations.set(commit.name, this))); } } remove(entity) { if (__classPrivateFieldGet(this, _Section_entities, "f").delete(entity.name) && entity instanceof Section) entity.position = SectionPosition.Group; } listOf(cls) { return [...__classPrivateFieldGet(this, _Section_entities, "f").values()].filter(value => value instanceof cls).sort(cls.compare); } } _Section_emoji = new WeakMap(), _Section_entities = new WeakMap(), _Section_order = new WeakMap(), _Section_position = new WeakMap(); export default Section;