UNPKG

augmented-string

Version:

Extends String methods adding: - lcFirst(): string; - ucFirst(): string; - ucWords(): string; - toFloat(): number; - toInt(): number; - toCamel(): string; - toKebab(): string; - toPascal(): string; - toSnake(): string; - repeat(count): string;

93 lines (92 loc) 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); const chai_1 = require("chai"); require("./index"); describe('String extension functions', () => { before(() => { }); describe('"123".toInt', () => { const testList = { '123': 123, '123ddd': 123, '123.456': 123 }; Object.entries(testList).forEach(([src, dst]) => it(`should convert "${src}" to ${dst}`, () => { (0, chai_1.expect)(src.toInt()).to.be.a('number'); (0, chai_1.expect)(src.toInt()).to.be.equal(dst); })); }); describe('"123.456".toFloat', () => { const testList = { '123.456': 123.456, '123.456aaa': 123.456 }; Object.entries(testList).forEach(([src, dst]) => it(`should convert "${src}" to ${dst}`, () => { (0, chai_1.expect)(src.toFloat()).to.be.a('number'); (0, chai_1.expect)(src.toFloat()).to.be.equal(dst); })); }); describe('"aaa".ucFirst', () => { it('should be string', () => { (0, chai_1.expect)('aaa'.ucFirst()).to.be.a('string'); }); it('should be "Aaa"', () => { (0, chai_1.expect)('aaa'.ucFirst()).to.be.equal('Aaa'); }); }); describe('"hello world!".ucWords', () => { it('should be string', () => { (0, chai_1.expect)('aaa'.ucWords()).to.be.a('string'); }); it('should be "Hello World!"', () => { (0, chai_1.expect)('hello world!'.ucWords()).to.be.equal('Hello World!'); }); }); describe('"AAA".lcFirst', () => { it('should be string', () => { (0, chai_1.expect)('AAA'.lcFirst()).to.be.a('string'); }); it('should be "aAA"', () => { (0, chai_1.expect)('AAA'.lcFirst()).to.be.equal('aAA'); }); }); describe('"aaa bbb ccc".toCamel', () => { const testList = { 'aaa_bbb_ccc': 'aaaBbbCcc', 'aaa-bbb-ccc': 'aaaBbbCcc', 'AaA bbB cCC': 'aaABbBCCC', 'Aaa Bbb Ccc': 'aaaBbbCcc', 'aa_a_bb_b_c_c_c': 'aaABbBCCC' }; Object.entries(testList).forEach(([src, dst]) => it(`should convert "${src}" to "${dst}"`, () => { (0, chai_1.expect)(src.toCamel()).to.be.a('string'); (0, chai_1.expect)(src.toCamel()).to.be.equal(dst); })); }); describe('"aaaBbbCcc".toSnake', () => { const testList = { 'aaa_bbb_ccc': 'aaa_bbb_ccc', 'aaa-bbb-ccc': 'aaa_bbb_ccc', 'AaA bbB cCC': 'aa_a_bb_b_c_c_c', 'Aaa Bbb Ccc': 'aaa_bbb_ccc' }; Object.entries(testList).forEach(([src, dst]) => it(`should convert "${src}" to "${dst}"`, () => { (0, chai_1.expect)(src.toSnake()).to.be.a('string'); (0, chai_1.expect)(src.toSnake()).to.be.equal(dst); })); }); describe('.toPascal', () => { const testList = { 'aaa_bbb_ccc': 'AaaBbbCcc', 'aaa-bbb-ccc': 'AaaBbbCcc', 'AaA bbB cCC': 'AaABbBCCC', 'Aaa Bbb Ccc': 'AaaBbbCcc', 'aa_a_bb_b_c_c_c': 'AaABbBCCC' }; Object.entries(testList).forEach(([src, dst]) => it(`should convert "${src}" to "${dst}"`, () => { (0, chai_1.expect)(src.toPascal()).to.be.a('string'); (0, chai_1.expect)(src.toPascal()).to.be.equal(dst); })); }); });