UNPKG

@egodigital/egoose

Version:

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

100 lines 4.09 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"); const WHITESPACES = " \t\r\n"; mocha_1.describe('#isEmptyString()', function () { mocha_1.describe('null', function () { mocha_1.it('should return (true) if input is (null)', function () { const RES = index_1.isEmptyString(null); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); }); }); mocha_1.describe('undefined', function () { mocha_1.it('should return (true) if input is (undefined)', function () { const RES = index_1.isEmptyString(undefined); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); }); }); mocha_1.describe('String', function () { mocha_1.it('should return (true) if input is an empty string', function () { const RES = index_1.isEmptyString(''); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); }); mocha_1.it('should return (true) if input contains whitespaces only', function () { for (let i = 1; i <= 1000; i++) { let str = ''; for (let j = 0; j < i; j++) { str += WHITESPACES[j % WHITESPACES.length]; } const RES = index_1.isEmptyString(str); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); } }); }); mocha_1.describe('Number', function () { mocha_1.it('should return (false) if input is 0', function () { const RES = index_1.isEmptyString(0); assert.ok('boolean' === typeof RES); assert.ok(!RES); assert.equal(RES, false); assert.strictEqual(RES, false); }); }); mocha_1.describe('Object', function () { mocha_1.it('should return (true) if #toString() of input returns empty string', function () { const RES = index_1.isEmptyString({ toString: () => '', }); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); }); mocha_1.it('should return (true) if #toString() of input returns whitespaces only', function () { for (let i = 1; i <= 1000; i++) { let str = ''; for (let j = 0; j < i; j++) { str += WHITESPACES[j % WHITESPACES.length]; } const RES = index_1.isEmptyString({ toString: () => str, }); assert.ok('boolean' === typeof RES); assert.ok(RES); assert.equal(RES, true); assert.strictEqual(RES, true); } }); }); }); //# sourceMappingURL=isEmptyString.js.map