From f6c5dfd62b966ec124de7b156b1bb58604c79a92 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Dec 2021 21:34:24 +0300 Subject: [PATCH] Added enum that describes dependency kinds --- src/metadata/dependency-kind.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/metadata/dependency-kind.ts diff --git a/src/metadata/dependency-kind.ts b/src/metadata/dependency-kind.ts new file mode 100644 index 0000000..0c6c6e4 --- /dev/null +++ b/src/metadata/dependency-kind.ts @@ -0,0 +1,33 @@ +enum DependencyKind { + Depends = 1, + Recommends, + Includes, + Suggests, + Conflicts, + Breaks, +} + +namespace DependencyKind { + export function getValues(): DependencyKind[] { + return Object.values(DependencyKind).filter(x => typeof x === "number"); + } + + export function parse(kindName: string): DependencyKind | undefined { + if (typeof DependencyKind[kindName] === "number") { + return DependencyKind[kindName]; + } + + for (const kind of Object.values(DependencyKind)) { + if (typeof kind === "number" && kindName.localeCompare(DependencyKind[kind], undefined, { sensitivity: "accent" }) === 0) { + return kind; + } + } + return undefined; + } + + export function toString(target: DependencyKind): string { + return DependencyKind[target] ?? target.toString(); + } +} + +export default DependencyKind;