@egodigital/egoose
Version:
Helper classes and functions for Node.js 10 or later.
99 lines • 4.21 kB
JavaScript
;
/**
* 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('#normalizeString()', function () {
mocha_1.describe('null', function () {
mocha_1.it('should return empty string if input is (null)', function () {
const RES = index_1.normalizeString(null);
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
});
});
mocha_1.describe('undefined', function () {
mocha_1.it('should return empty string if input is (undefined)', function () {
const RES = index_1.normalizeString(undefined);
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
});
});
mocha_1.describe('String', function () {
mocha_1.it('should return empty string if input is an empty string', function () {
const RES = index_1.normalizeString('');
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
});
mocha_1.it('should return empty string 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.normalizeString(str);
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
}
});
mocha_1.it('should return lower case, trimmed version of an input string', function () {
const RES = index_1.normalizeString(' Mk + tM ');
assert.ok('string' === typeof RES);
assert.equal(RES, 'mk + tm');
assert.strictEqual(RES, 'mk + tm');
});
});
mocha_1.describe('Number', function () {
mocha_1.it('should return "0" if input is 0', function () {
const RES = index_1.normalizeString(0);
assert.ok('string' === typeof RES);
assert.equal(RES, '0');
assert.strictEqual(RES, '0');
});
});
mocha_1.describe('Object', function () {
mocha_1.it('should return empty string if #toString() of input returns empty string', function () {
const RES = index_1.normalizeString({
toString: () => '',
});
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
});
mocha_1.it('should return empty string if #toString() of 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.normalizeString({
toString: () => str,
});
assert.ok('string' === typeof RES);
assert.equal(RES, '');
assert.strictEqual(RES, '');
}
});
});
});
//# sourceMappingURL=normalizeString.js.map