-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9317a50
Showing
11 changed files
with
2,567 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
coverage/ | ||
dist/ | ||
node_modules/ | ||
|
||
testes/exemplo2.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Testes unitários", | ||
"type": "node", | ||
"request": "launch", | ||
"runtimeArgs": [ | ||
"--inspect-brk", | ||
"${workspaceRoot}/node_modules/jest/bin/jest.js", | ||
"--runInBand" | ||
], | ||
"skipFiles": ["<node_internals>/**", "node_modules/**"], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Design Líquido | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# delegua-json | ||
|
||
Biblioteca para manipulação de JSON. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as sistemaArquivos from "node:fs" | ||
import * as caminho from "node:path" | ||
|
||
export function importarArquivoJson(caminhoArquivo: string): any { | ||
const caminhoResolvido = caminho.resolve(caminhoArquivo); | ||
const dadosDoArquivo: Buffer = sistemaArquivos.readFileSync(caminhoResolvido); | ||
return JSON.parse(dadosDoArquivo.toString()); | ||
} | ||
|
||
export function exportarObjetoParaArquivoJson(conteudoJson: any, caminhoArquivo: string) { | ||
const conteudoTratado = JSON.stringify(conteudoJson); | ||
sistemaArquivos.writeFileSync(caminhoArquivo, conteudoTratado); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
export default async (): Promise<Config.InitialOptions> => { | ||
return { | ||
verbose: true, | ||
modulePathIgnorePatterns: ['<rootDir>/dist/'], | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
coverageReporters: ['text', 'text-summary', 'lcov'], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@designliquido/delegua-json", | ||
"description": "Biblioteca para Delégua e JavaScript para manipulação de JSON.", | ||
"author": "Leonel Sanches da Silva", | ||
"scripts": { | ||
"testes-unitarios": "jest --coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.2.4", | ||
"@types/node": "^18.11.15", | ||
"jest": "^29.3.1", | ||
"ts-jest": "^29.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { exportarObjetoParaArquivoJson, importarArquivoJson } from ".."; | ||
|
||
describe("Métodos que trabalham com arquivos", () => { | ||
it("Arquivo para JSON", () => { | ||
const retorno = importarArquivoJson("./testes/exemplo.json"); | ||
expect(retorno).toBeTruthy(); | ||
expect(retorno.funcionarios).toBeTruthy(); | ||
expect(retorno.funcionarios).toHaveLength(11); | ||
expect(retorno.areas).toBeTruthy(); | ||
expect(retorno.areas).toHaveLength(3); | ||
}); | ||
|
||
it("JSON para arquivo", () => { | ||
const retorno = exportarObjetoParaArquivoJson({ | ||
"funcionarios": [ | ||
{ | ||
"id": 0, | ||
"nome": "Marcelo", | ||
"sobrenome": "Silva", | ||
"salario": 3200.00, | ||
"area": "SM" | ||
}, | ||
{ | ||
"id": 1, | ||
"nome": "Washington", | ||
"sobrenome": "Ramos", | ||
"salario": 2700.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 2, | ||
"nome": "Sergio", | ||
"sobrenome": "Pinheiro", | ||
"salario": 2450.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 3, | ||
"nome": "Bernardo", | ||
"sobrenome": "Costa", | ||
"salario": 3700.00, | ||
"area": "SM" | ||
}, | ||
{ | ||
"id": 4, | ||
"nome": "Cleverton", | ||
"sobrenome": "Farias", | ||
"salario": 2750.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 5, | ||
"nome": "Abraão", | ||
"sobrenome": "Campos", | ||
"salario": 2550.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 6, | ||
"nome": "Letícia", | ||
"sobrenome": "Farias", | ||
"salario": 2450.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 7, | ||
"nome": "Fernando", | ||
"sobrenome": "Ramos", | ||
"salario": 2450.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 8, | ||
"nome": "Marcelo", | ||
"sobrenome": "Farias", | ||
"salario": 2550.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 9, | ||
"nome": "Fabio", | ||
"sobrenome": "Souza", | ||
"salario": 2750.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 10, | ||
"nome": "Clederson", | ||
"sobrenome": "Oliveira", | ||
"salario": 2500.00, | ||
"area": "SD" | ||
} | ||
], | ||
"areas": [ | ||
{ | ||
"codigo": "SD", | ||
"nome": "Desenvolvimento de Software" | ||
}, | ||
{ | ||
"codigo": "SM", | ||
"nome": "Gerenciamento de Software" | ||
}, | ||
{ | ||
"codigo": "UD", | ||
"nome": "Designer de UI/UX" | ||
} | ||
] | ||
}, "./testes/exemplo2.json"); | ||
|
||
const jsonExportado = importarArquivoJson("./testes/exemplo2.json"); | ||
expect(jsonExportado).toBeTruthy(); | ||
expect(jsonExportado.funcionarios).toBeTruthy(); | ||
expect(jsonExportado.funcionarios).toHaveLength(11); | ||
expect(jsonExportado.areas).toBeTruthy(); | ||
expect(jsonExportado.areas).toHaveLength(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"funcionarios": [ | ||
{ | ||
"id": 0, | ||
"nome": "Marcelo", | ||
"sobrenome": "Silva", | ||
"salario": 3200.00, | ||
"area": "SM" | ||
}, | ||
{ | ||
"id": 1, | ||
"nome": "Washington", | ||
"sobrenome": "Ramos", | ||
"salario": 2700.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 2, | ||
"nome": "Sergio", | ||
"sobrenome": "Pinheiro", | ||
"salario": 2450.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 3, | ||
"nome": "Bernardo", | ||
"sobrenome": "Costa", | ||
"salario": 3700.00, | ||
"area": "SM" | ||
}, | ||
{ | ||
"id": 4, | ||
"nome": "Cleverton", | ||
"sobrenome": "Farias", | ||
"salario": 2750.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 5, | ||
"nome": "Abraão", | ||
"sobrenome": "Campos", | ||
"salario": 2550.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 6, | ||
"nome": "Letícia", | ||
"sobrenome": "Farias", | ||
"salario": 2450.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 7, | ||
"nome": "Fernando", | ||
"sobrenome": "Ramos", | ||
"salario": 2450.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 8, | ||
"nome": "Marcelo", | ||
"sobrenome": "Farias", | ||
"salario": 2550.00, | ||
"area": "UD" | ||
}, | ||
{ | ||
"id": 9, | ||
"nome": "Fabio", | ||
"sobrenome": "Souza", | ||
"salario": 2750.00, | ||
"area": "SD" | ||
}, | ||
{ | ||
"id": 10, | ||
"nome": "Clederson", | ||
"sobrenome": "Oliveira", | ||
"salario": 2500.00, | ||
"area": "SD" | ||
} | ||
], | ||
"areas": [ | ||
{ | ||
"codigo": "SD", | ||
"nome": "Desenvolvimento de Software" | ||
}, | ||
{ | ||
"codigo": "SM", | ||
"nome": "Gerenciamento de Software" | ||
}, | ||
{ | ||
"codigo": "UD", | ||
"nome": "Designer de UI/UX" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"module": "commonjs", | ||
"target": "es2017", | ||
"rootDir": ".", | ||
"allowJs": true, | ||
"sourceMap": true, | ||
"declaration": true, | ||
"esModuleInterop": true | ||
}, | ||
"exclude": ["babel.config.js", "dist/**/*"] | ||
} |
Oops, something went wrong.