UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

91 lines 3.95 kB
"use strict"; /** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); const assert = require("assert"); const mocha_1 = require("mocha"); const index_1 = require("../index"); mocha_1.describe('#toStringSafe()', function () { mocha_1.describe('(null)', function () { mocha_1.it('should return empty string when the value is (null)', function () { const RES = index_1.toStringSafe(null); assert.ok('string' === typeof RES); assert.equal(RES, ''); assert.strictEqual(RES, ''); }); mocha_1.it('should return custom default value when the value is (null)', function () { const RES = index_1.toStringSafe(null, 'MK'); assert.ok('string' === typeof RES); assert.equal(RES, 'MK'); assert.strictEqual(RES, 'MK'); }); }); mocha_1.describe('(undefined)', function () { mocha_1.it('should return empty string when the value is (undefined)', function () { const RES = index_1.toStringSafe(undefined); assert.ok('string' === typeof RES); assert.equal(RES, ''); assert.strictEqual(RES, ''); }); mocha_1.it('should return custom default value when the value is (undefined)', function () { const RES = index_1.toStringSafe(undefined, 'TM'); assert.ok('string' === typeof RES); assert.equal(RES, 'TM'); assert.strictEqual(RES, 'TM'); }); }); mocha_1.describe('String', function () { mocha_1.it('should return same value when the value is of type String', function () { const RES = index_1.toStringSafe('JS'); assert.ok('string' === typeof RES); assert.equal(RES, 'JS'); assert.strictEqual(RES, 'JS'); }); }); mocha_1.describe('Number', function () { mocha_1.it('should return string representation when the value is of type integer', function () { for (let i = 0; i < 1000; i++) { const RES = index_1.toStringSafe(i); assert.ok('string' === typeof RES); assert.equal(RES, '' + i); assert.strictEqual(RES, '' + i); } }); mocha_1.it('should return string representation when the value is of type float', function () { for (let i = 0; i < 1000; i++) { const NR = i / 10.0; const RES = index_1.toStringSafe(NR); assert.ok('string' === typeof RES); assert.equal(RES, '' + NR); assert.strictEqual(RES, '' + NR); } }); }); mocha_1.describe('Object', function () { mocha_1.it('should return result of #toString() method when the value is an object', function () { const RES = index_1.toStringSafe({ toString: () => { return 'MK+TM'; }, }); assert.ok('string' === typeof RES); assert.equal(RES, 'MK+TM'); assert.strictEqual(RES, 'MK+TM'); }); }); }); //# sourceMappingURL=toStringSafe.js.map