inverter_caixa-yan-senai 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Index.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Inverte a caixa (maiúsculas/minúsculas) de um texto: Maiúsculas se tornam minúsculas e vice-versa.
3
+ *
4
+ * @param {string} texto - O texto a ser invertido.
5
+ * @returns {string} O texto com a caixa invertida.
6
+ *
7
+ *
8
+ * Exemplo:
9
+ * Invertendo a caixa do texto "Olá Mundo"; "oLÁ mUNDO".
10
+ */
11
+ function inverterCaixa(texto) {
12
+ if (typeof texto !== 'string') {
13
+ throw new TypeError('O argumento deve ser uma string.');
14
+ }
15
+
16
+ let resultado = '';
17
+ for (const caractere of texto) {
18
+ const menor = caractere.toLowerCase();
19
+ const maior = caractere.toUpperCase();
20
+
21
+ if (caractere === menor && caractere !== maior) {
22
+ //é minúscula, então converte para maiúscula
23
+ resultado += maior;
24
+ } else if (caractere === maior && caractere !== menor) {
25
+ //é maiúscula, então converte para minúscula
26
+ resultado += menor;
27
+ } else {
28
+ //não é letra, então mantém o mesmo caractere
29
+ resultado += caractere;
30
+ }
31
+ }
32
+ return resultado;
33
+ }
34
+
35
+ module.exports = inverterCaixa;
36
+ module.exports.inverterCaixa = inverterCaixa;
37
+ module.exports.default = inverterCaixa;
package/Readme ADDED
File without changes
package/index.test.js ADDED
@@ -0,0 +1,25 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert');
3
+ const inverterCaixa = require('./index.js');
4
+
5
+ test('Inverte letras maiúsculas e minúsculas simples', () => {
6
+ assert.strictEqual(inverterCaixa('Olá Mundo!'), 'oLÁ mUNDO!');
7
+ });
8
+
9
+ test('funciona com string totalmente minúscula', () => {
10
+ assert.strictEqual(inverterCaixa('javascript'), 'JAVASCRIPT');
11
+ });
12
+
13
+ test('funciona com string vazia', () => {
14
+ assert.strictEqual(inverterCaixa(''), '');
15
+ });
16
+
17
+ test('funciona com acentos', () => {
18
+ assert.strictEqual(inverterCaixa('Ação Café'), 'aÇÃO cAFÉ');
19
+ });
20
+
21
+ test('lança erro se não receber uma string', () => {
22
+ assert.throws(() => inverterCaixa(123), TypeError);
23
+ assert.throws(() => inverterCaixa(null), TypeError);
24
+ assert.throws(() => inverterCaixa(undefined), TypeError);
25
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "inverter_caixa-yan-senai",
3
+ "version": "1.0.0",
4
+ "description": "Inverte a caixa (maiúsculas/minúsculas) de um texto: Maiúsculas se tornam minúsculas e vice-versa.",
5
+ "main": "index.js",
6
+ "exports": {
7
+ "require": "./index.js",
8
+ "import": "./index.mjs"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "module": "commonjs"
17
+ }