UNPKG

@mosmmy/shortname-js

Version:

shortname-js is a JavaScript function designed to shorten names in a simple and user-friendly way. The function allows users to quickly enter full names and receive abbreviated versions of those names in return

52 lines (51 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); describe('shortName', () => { test('should format simple first and last name', () => { expect((0, index_1.shortName)('John Doe')).toBe('John Doe'); }); test('should format name with middle name', () => { expect((0, index_1.shortName)(' John James Doe ')).toBe('John J. Doe'); }); test('should format name with multiple middle names', () => { expect((0, index_1.shortName)('John James Robert Doe')).toBe('John J. R. Doe'); }); test('should handle prepositions correctly', () => { expect((0, index_1.shortName)('João da Silva')).toBe('João da Silva'); expect((0, index_1.shortName)('Maria do Santos')).toBe('Maria do Santos'); expect((0, index_1.shortName)('Pedro dos Reis')).toBe('Pedro dos Reis'); }); test('should handle number in name', () => { expect((0, index_1.shortName)('Mário Pedro4 António')).toBe('Mário P. António'); expect((0, index_1.shortName)('4MAteus Pereira dos4 Santos')).toBe('Mateus P. dos Santos'); expect((0, index_1.shortName)('Luiz 4de Jesus5 Mateus3 d1e Almeida3')).toBe('Luiz J. M. de Almeida'); expect((0, index_1.shortName)('Marciano3 3 Âng3elo e3 3 Sim3ão de 3Almeida')).toBe('Marciano A. S. de Almeida'); expect((0, index_1.shortName)('Julia Ward Howe 1819-1910')).toBe('Julia W. Howe'); expect((0, index_1.shortName)('1819 - 435&%$#"!*?=)(/&&%$#"~_:;.;, Julia 56.090º~-."\\,~ Ward Howe 1819-1910')).toBe('Julia W. Howe'); }); test('should handle characters and number in name ', () => { expect((0, index_1.shortName)('1819 - 435&%$#"!*?=)(/&&%$#"~_:;.;, Julia 56.090º~-."\\,~ Ward Howe 1819-1910')).toBe('Julia W. Howe'); }); test('should handle accented characters', () => { expect((0, index_1.shortName)('José María Rodriguez')).toBe('José M. Rodriguez'); expect((0, index_1.shortName)('António Marta dos Prazeres')).toBe('António M. dos Prazeres'); expect((0, index_1.shortName)('Ângelo de Jesus Mateus de Almeida')).toBe('Ângelo J. M. de Almeida'); expect((0, index_1.shortName)('Marciâno Ângelo e Simão de Almeida')).toBe('Marciâno A. S. de Almeida'); expect((0, index_1.shortName)('Moça Ângelo e Simão de Almeida')).toBe('Moça A. S. de Almeida'); }); test('should handle multiple prepositions and middle names', () => { expect((0, index_1.shortName)('Ana de Maria da Silva Santos')).toBe('Ana M. S. Santos'); expect((0, index_1.shortName)(' João da 4545\´<. Pedro dos Santos João Silveira ')).toBe('João P. S. J. Silveira'); expect((0, index_1.shortName)(' de da João Pedro dos Santos Silveira ')).toBe('João P. S. Silveira'); }); test('should handle single name', () => { expect((0, index_1.shortName)('John')).toBe('John'); }); test('should handle empty string', () => { expect((0, index_1.shortName)('')).toBeUndefined(); }); test('should handle numbers', () => { expect((0, index_1.shortName)('343434343434')).toBeUndefined(); }); });