UNPKG

topkat-utils

Version:

A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.

77 lines 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assert = exports.restTestMini = void 0; //---------------------------------------- // TESTS UTILS //---------------------------------------- const logger_utils_1 = require("./logger-utils"); const isset_1 = require("./isset"); const validation_utils_1 = require("./validation-utils"); const is_object_1 = require("./is-object"); exports.restTestMini = { throwOnErr: false, reset(throwOnErr = false) { exports.restTestMini.nbSuccess = 0; exports.restTestMini.nbError = 0; exports.restTestMini.lastErrors = []; exports.restTestMini.throwOnErr = throwOnErr; }, newErr(err) { exports.restTestMini.nbError++; exports.restTestMini.lastErrors.push(err); if (exports.restTestMini.throwOnErr) throw new Error(err); else logger_utils_1.C.error(false, err); }, printStats() { // TODO print last errz logger_utils_1.C.info(`ERRORS RESUME =========`); if (exports.restTestMini.lastErrors.length) logger_utils_1.C.log('\n\n\n'); for (const lastErr of exports.restTestMini.lastErrors) logger_utils_1.C.error(false, lastErr); logger_utils_1.C.log('\n\n\n'); logger_utils_1.C.info(`STATS =========`); logger_utils_1.C.info(`Total: ${exports.restTestMini.nbSuccess + exports.restTestMini.nbError}`); logger_utils_1.C.success(`Success: ${exports.restTestMini.nbSuccess}`); logger_utils_1.C.error(false, ` Errors: ${exports.restTestMini.nbError}`); }, nbSuccess: 0, nbError: 0, lastErrors: [] }; /** if validatorObject param is not set then it will consider checking that the value is set * * @param description * @param value * @param validatorObject */ function assert(description, value, validatorObject) { try { const validatorObjReal = { value, name: description, }; if ((0, is_object_1.isObject)(validatorObject)) Object.assign(validatorObjReal, validatorObject); else if ((0, isset_1.isset)(validatorObject)) validatorObjReal.eq = validatorObject; const issetCheck = !(0, isset_1.isset)(validatorObjReal); // isEmpty() const [errMsg, extraInfos] = (0, validation_utils_1.validatorReturnErrArray)(validatorObjReal); const msg2 = description + ` ${issetCheck ? 'isset' : `${JSON.stringify(validatorObject)}`}`; if ((0, isset_1.isset)(errMsg)) { const err = msg2 + `\n ${errMsg}\n ${JSON.stringify(extraInfos)}`; exports.restTestMini.newErr(err); } else { exports.restTestMini.nbSuccess++; logger_utils_1.C.success(msg2); } } catch (err) { exports.restTestMini.newErr(err); } } exports.assert = assert; //# sourceMappingURL=tests-utils.js.map