UNPKG

changelog-guru

Version:
105 lines (104 loc) 4.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 _Commit_accents, _Commit_changeType, _Commit_replacements, _Commit_subject, _Commit_type; import LookupManager from 'string-lookup-manager'; import { splitHeadline } from '../../utils/commit.js'; import { wrap } from '../../utils/markdown.js'; import Entity, { ChangeLevel, Compare, Priority } from './Entity.js'; export var CommitChangeType; (function (CommitChangeType) { CommitChangeType[CommitChangeType["BreakingChanges"] = 1] = "BreakingChanges"; CommitChangeType[CommitChangeType["Deprecated"] = 2] = "Deprecated"; CommitChangeType[CommitChangeType["Important"] = 4] = "Important"; CommitChangeType[CommitChangeType["Default"] = 8] = "Default"; })(CommitChangeType || (CommitChangeType = {})); const COMMIT_SHOT_NAME_LENGTH = 7; class Commit extends Entity { constructor({ hash, timestamp, headline, body, url, author }) { super(hash); this.body = []; _Commit_accents.set(this, new Set()); _Commit_changeType.set(this, CommitChangeType.Default); _Commit_replacements.set(this, new LookupManager()); _Commit_subject.set(this, ''); _Commit_type.set(this, void 0); this.timestamp = timestamp; this.url = url; this.author = author; const [type, scope, subject] = splitHeadline(headline); if (type) __classPrivateFieldSet(this, _Commit_type, type.toLocaleLowerCase(), "f"); if (scope) this.scope = scope; if (subject) __classPrivateFieldSet(this, _Commit_subject, subject, "f"); if (body) this.body = body.split('\n').map(line => line.trim()); } static compare(a, b) { const { scope: x } = a; const { scope: y } = b; let result = super.compare(a, b); if (x && !y) result--; if (!x && y) result++; if (x && y) result = x.localeCompare(y); if (result === Compare.Equal) result = a.timestamp - b.timestamp; return Math.min(Math.max(result, Compare.Less), Compare.More); } get accents() { return [...__classPrivateFieldGet(this, _Commit_accents, "f").values()]; } get type() { return __classPrivateFieldGet(this, _Commit_type, "f") ?? ''; } get priority() { let priority = super.priority; if (this.is(CommitChangeType.BreakingChanges)) priority += Priority.High; if (this.is(CommitChangeType.Deprecated)) priority += Priority.Medium; if (this.is(CommitChangeType.Important)) priority += Priority.Low; return priority; } get subject() { return __classPrivateFieldGet(this, _Commit_replacements, "f").replace(__classPrivateFieldGet(this, _Commit_subject, "f"), item => wrap(item.value)); } get changeType() { return __classPrivateFieldGet(this, _Commit_changeType, "f"); } set changeType(type) { __classPrivateFieldSet(this, _Commit_changeType, __classPrivateFieldGet(this, _Commit_changeType, "f") | type, "f"); if (this.is(CommitChangeType.Deprecated)) this.level = ChangeLevel.Minor; if (this.is(CommitChangeType.BreakingChanges)) this.level = ChangeLevel.Major; } get shortName() { return this.name.substr(0, COMMIT_SHOT_NAME_LENGTH); } accent(text) { __classPrivateFieldGet(this, _Commit_accents, "f").add(text); } is(type) { return !!(__classPrivateFieldGet(this, _Commit_changeType, "f") & type); } replacement(value, position) { __classPrivateFieldGet(this, _Commit_replacements, "f").add(value, position); } } _Commit_accents = new WeakMap(), _Commit_changeType = new WeakMap(), _Commit_replacements = new WeakMap(), _Commit_subject = new WeakMap(), _Commit_type = new WeakMap(); export default Commit;