UNPKG

@testyard/stats

Version:
58 lines (55 loc) 1.59 kB
/*! * @testyard/stats v1.4.1 * https://github.com/testyardjs/stats * * Copyright (c) 2023 Richard King <richrdkng@gmail.com> (https://richrdkng.com) * Released under the MIT License * https://github.com/testyardjs/stats/blob/main/LICENSE * * Date: 2023-07-19T13:11:26.750Z */ 'use strict'; class BooleanStats { constructor() { this._numTrue = 0; this._numFalse = 0; this._numAdded = 0; // private _isSummarized = false // constructor () {} this.add = (value) => { if (typeof value !== 'boolean') { throw new Error(`value should be boolean, got: ${typeof value}.`); } // eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare if (value === true) { this._numTrue++; } else { this._numFalse++; } this._numAdded++; }; } get result() { // @ts-expect-error const object = {}; const props = { true: { get: () => ({ total: this._numTrue, percent: this._numTrue / this._numAdded }) }, false: { get: () => ({ total: this._numFalse, percent: this._numFalse / this._numAdded }) } }; Object.defineProperties(object, props); return object; } } module.exports = BooleanStats; //# sourceMappingURL=index.js.map