// Copyright (c) Catgirl Enterprises - Licensed under MIT // Check LICENSE in repository root for more information. import IMetric from "../interfaces/IMetric"; export default class Counter implements IMetric { private _name:string; private _helpText:string; private _value:number; public constructor(name:string) { this._name = name; this._helpText = ""; this._value = 0; } public get name() { return this._name; } public get Value() { return this._value; } public set Value(value:number) { throw "Cannot set the Value of a counter. Counters can only added to with the add method."; } public add(value:number) { this._value += value; } public setHelpText(value:string) { this._helpText = value; } public toString() { return `${this._helpText.length > 0 ? `# HELP ${this._name} ${this._helpText}\n` : ""}# TYPE ${this._name} counter\n${this._name} ${this.Value}\n`; } }