datamachine
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,11 +0,10 @@ | ||
[{"name":"Antonina Schroeder","cpf":"067.710.318-29","nascimento":"1993-09-21T15:43:43.000Z","curso":"Letras","mediaEnem":917.52} | ||
,{"name":"Coralie Yost","cpf":"514.495.434-05","nascimento":"1992-12-12T16:42:46.000Z","curso":"Engenharia de Computação","mediaEnem":363.49} | ||
,{"name":"John Wintheiser","cpf":"632.071.773-44","nascimento":"1992-07-26T01:23:58.000Z","curso":"Medicina","mediaEnem":616.64} | ||
,{"name":"Dolores Murazik","cpf":"145.943.869-89","nascimento":"1993-05-20T16:06:52.000Z","curso":"Comunicação Social","mediaEnem":820.87} | ||
,{"name":"Aron Runte","cpf":"857.366.231-02","nascimento":"1991-07-23T11:20:50.000Z","curso":"Comunicação Social","mediaEnem":644.81} | ||
,{"name":"Mr. Caitlyn Weissnat","cpf":"034.723.997-83","nascimento":"1992-12-16T17:40:37.000Z","curso":"Comunicação Social","mediaEnem":580.27} | ||
,{"name":"Marisol Friesen","cpf":"363.207.003-27","nascimento":"1992-12-04T23:45:00.000Z","curso":"Medicina","mediaEnem":711.27} | ||
,{"name":"Ardella Hettinger","cpf":"925.747.039-36","nascimento":"1991-03-02T17:52:41.000Z","curso":"Engenharia de Computação","mediaEnem":645.36} | ||
,{"name":"Freeman Senger","cpf":"449.370.375-01","nascimento":"1991-01-31T19:50:11.000Z","curso":"Engenharia de Computação","mediaEnem":308.84} | ||
,{"name":"Rocky Runte","cpf":"517.723.566-11","nascimento":"1993-12-18T05:40:12.000Z","curso":"Medicina","mediaEnem":912.72} | ||
] | ||
[{"nome":"Andy Satterfield","cpf":"247.616.841-60","celular":"(20) 29522-1471","nascimento":"1991-04-11T03:31:46.000Z","mediaEnem":420.16}, | ||
{"nome":"Kassandra Fritsch","cpf":"064.792.013-10","celular":"(57) 96832-8375","nascimento":"1993-10-01T02:35:32.000Z","mediaEnem":670.11}, | ||
{"nome":"Julia Wunsch","cpf":"011.899.380-14","celular":"(35) 75129-7627","nascimento":"1991-11-12T19:11:47.000Z","mediaEnem":349.98}, | ||
{"nome":"Isac Mraz","cpf":"099.149.713-93","celular":"(09) 04887-4573","nascimento":"1991-06-07T08:10:28.000Z","mediaEnem":859.29}, | ||
{"nome":"Stephan Stokes","cpf":"664.392.955-51","celular":"(17) 87606-5149","nascimento":"1992-09-26T09:09:34.000Z","mediaEnem":808.4}, | ||
{"nome":"Brenda Kuhic","cpf":"711.605.060-43","celular":"(17) 89041-9103","nascimento":"1992-09-20T21:17:32.000Z","mediaEnem":517.73}, | ||
{"nome":"Mackenzie Halvorson III","cpf":"750.819.130-73","celular":"(66) 02773-5420","nascimento":"1993-02-17T05:49:35.000Z","mediaEnem":333.01}, | ||
{"nome":"Jarvis Feest","cpf":"374.629.670-65","celular":"(45) 33498-0008","nascimento":"1993-04-21T13:17:07.000Z","mediaEnem":904.73}, | ||
{"nome":"Bernardo Sporer","cpf":"742.845.194-92","celular":"(31) 61170-7157","nascimento":"1993-05-22T18:52:31.000Z","mediaEnem":638.99}, | ||
{"nome":"Bernhard Predovic","cpf":"347.875.953-69","celular":"(18) 71639-3338","nascimento":"1991-12-03T10:33:26.000Z","mediaEnem":709.38}] |
@@ -1,9 +0,7 @@ | ||
var molds = []; | ||
molds.push({ | ||
name: 'name', | ||
module.exports = [{ | ||
nome: 'name', | ||
cpf: 'cpf', | ||
celular: /(\(\d{2}\) \d{5}\-\d{4})/, | ||
nascimento: 'date:1990;1994', | ||
curso: 'enum:Engenharia de Computação;Medicina;Letras;Comunicação Social', | ||
mediaEnem: 'decimal:2;300;1000' | ||
}); | ||
module.exports = molds; | ||
}] |
95
index.js
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
var getFilePath = require('./src/helpers/getFilePath'); | ||
var combineArraysOfObjects = require('./src/combine-arrays-of-objects'); | ||
@@ -56,3 +57,97 @@ program | ||
program | ||
.command('combine <file1> <file2>') | ||
.alias('c') | ||
.option("--chl, --child <child>", "Incluir o segundo objeto como um filho do primeiro, setando um nome para a chave. Ex.: --child nome-da-chave") | ||
.option("--on, --outname <child>", "Definir nome do arquivo de saída. Ex.: --outname nome-do-arquivo") | ||
.description('Combinar objetos de duas coleções diferentes') | ||
.action((file1Name, file2Name, options) => { | ||
console.log(`Lendo o arquivo ${file1Name}...`); | ||
let file1Path = getFilePath(file1Name); | ||
let file1 = require(file1Path); | ||
console.log(`Lendo o arquivo ${file2Name}...`); | ||
let file2Path = getFilePath(file2Name); | ||
let file2 = require(file2Path); | ||
console.log(`Combinando os dados...`); | ||
let combinedArrays = combineArraysOfObjects(file1, file2, options.child); | ||
let output = 'json'; | ||
let fileNamePattern = /^([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+\/)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+.json$/; | ||
let file1NameWithOutExtension; | ||
let file2NameWithOutExtension; | ||
let file1NameWithOutFolders; | ||
let file2NameWithOutFolders; | ||
if(fileNamePattern.test(file1Name)){ | ||
file1NameWithOutFolders = file1Name.match(/[\w\d À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]+.json$/); | ||
file1NameWithOutExtension = file1NameWithOutFolders[0].split('.'); | ||
} | ||
if(fileNamePattern.test(file1Name)){ | ||
file2NameWithOutFolders = file2Name.match(/[\w\d À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]+.json$/); | ||
file2NameWithOutExtension = file2NameWithOutFolders[0].split('.'); | ||
} | ||
let outputName | ||
if(options.outname){ | ||
outputName = options.outname | ||
}else{ | ||
outputName = `${file1NameWithOutExtension[0]}-combined-with-${file2NameWithOutExtension[0]}`; | ||
} | ||
console.log("Gerando arquivo de saída..."); | ||
generateOutput(output, combinedArrays, outputName); | ||
}); | ||
program | ||
.command('adapt-to-json-server <file>') | ||
.alias('2server') | ||
.option("--ep, --end-point-name <name>", "Definir nome do end point. Ex.: --end-point-name nome-do-end-point") | ||
.description('Adaptar coleção de dados para funcionar com json-server') | ||
.action((fileName, options) => { | ||
let output = 'json'; | ||
console.log(`Lendo o arquivo ${fileName}...`); | ||
let filePath = getFilePath(fileName); | ||
let file = require(filePath); | ||
console.log("--------"); | ||
let fileNamePattern = /^([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+\/)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+.json$/; | ||
let fileNameWithOutFolders; | ||
let fileNameWithOutExtension; | ||
if(fileNamePattern.test(fileName)){ | ||
fileNameWithOutFolders = fileName.match(/[\w\d À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]+.json$/); | ||
fileNameWithOutExtension = fileNameWithOutFolders[0].split('.'); | ||
} | ||
console.log(fileNameWithOutExtension); | ||
let jsonServer; | ||
if(options.endPointName){ | ||
jsonServer = { | ||
[options.endPointName]: file | ||
}; | ||
generateOutput(output, jsonServer, options.endPointName); | ||
}else{ | ||
jsonServer = { | ||
[fileNameWithOutExtension[0]]: file | ||
}; | ||
generateOutput(output, jsonServer, `${fileNameWithOutExtension[0]}.server.json`); | ||
} | ||
}); | ||
program.parse(process.argv); | ||
{ | ||
"name": "datamachine", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Datamachine is a CLI tool for manufacturing mock data", | ||
@@ -44,3 +44,4 @@ "author": { | ||
"commander": "^2.18.0", | ||
"faker": "^4.1.0" | ||
"faker": "^4.1.0", | ||
"randexp": "^0.5.3" | ||
}, | ||
@@ -47,0 +48,0 @@ "devDependencies": { |
# datamachine | ||
Esta ferramenta CLI produz dados falsos com realismo e precisão | ||
Com esta ferramenta CLI você pode produzir dados falsos com realismo e precisão para simular API's, bancos de dados e estados de aplicação. Para gerar os dados, ela utiliza bibliotecas como chance.js, Faker.js e randexp.js. | ||
@@ -16,15 +16,14 @@ ### Installation | ||
``` | ||
var molds = []; | ||
molds.push({ | ||
name: 'name', | ||
module.exports = [{ | ||
nome: 'name', | ||
cpf: 'cpf', | ||
celular: /(\(\d{2}\) \d{5}\-\d{4})/, | ||
nascimento: 'date:1990;1994', | ||
curso: 'enum:Engenharia de Computação;Medicina;Letras;Comunicação Social', | ||
mediaEnem: 'decimal:2;300;1000' | ||
}); | ||
module.exports = molds; | ||
}] | ||
``` | ||
Então os dados podem ser gerados através do comando __datamachine generate__, como por exemplo: | ||
``` | ||
$ datamachine generate candidato.schema.js 10 | ||
$ datamachine generate candidato.schema.js 5 | ||
``` | ||
@@ -34,12 +33,7 @@ Este comando cria um array com 10 objetos, estruturados segundo os schema informado no arquivo __candidato.schema.js__. Ele gera um arquivo com o nome __data.json__, que contém os dados gerados. Por exemplo, o comando supracitado pode gerar o _json_ abaixo. | ||
``` | ||
[{"name":"Henry Labadie","cpf":"259.079.375-80","nascimento":"1992-07-08T09:00:18.000Z","curso":"Letras","mediaEnem":"817.67"}, | ||
{"name":"Luigi Goodwin","cpf":"887.295.600-55","nascimento":"1992-12-20T11:30:32.000Z","mediaEnem":"324.16"}, | ||
{"name":"Jesus Dare","cpf":"685.405.782-55","nascimento":"1991-01-24T13:46:49.000Z","mediaEnem":"636.01"}, | ||
{"name":"Dr. Kenna Tillman","cpf":"514.215.299-98","nascimento":"1993-07-21T16:38:00.000Z","mediaEnem":"898.92"}, | ||
{"name":"Rodolfo Waelchi","cpf":"365.512.467-88","nascimento":"1992-06-12T17:02:50.000Z","mediaEnem":"355.73"}, | ||
{"name":"Doyle Kutch","cpf":"984.622.157-65","nascimento":"1993-07-22T06:25:09.000Z","mediaEnem":"306.28"}, | ||
{"name":"Eveline Moore","cpf":"146.971.653-49","nascimento":"1993-05-19T08:37:48.000Z","mediaEnem":"386.64"}, | ||
{"name":"Hope Sporer","cpf":"913.349.720-60","nascimento":"1992-03-20T14:24:23.000Z","mediaEnem":"577.75"}, | ||
{"name":"Chanelle Cummings MD","cpf":"417.434.903-72","nascimento":"1992-03-06T23:50:03.000Z","mediaEnem":"855.17"}, | ||
{"name":"Emilia Bahringer","cpf":"464.458.705-20","nascimento":"1993-02-21T13:09:34.000Z","mediaEnem":"827.90"}] | ||
[{"nome":"Andrew Goyette","cpf":"874.281.534-76","celular":"(31) 55190-5339","nascimento":"1992-01-21T10:19:27.000Z","curso":"Letras","mediaEnem":762.97}, | ||
{"nome":"Bettye Legros","cpf":"455.159.591-83","celular":"(18) 93105-3613","nascimento":"1993-10-24T01:18:09.000Z","curso":"Comunicação Social","mediaEnem":961.82}, | ||
{"nome":"Ressie Donnelly","cpf":"507.009.678-85","celular":"(45) 58872-4444","nascimento":"1993-10-18T00:29:04.000Z","curso":"Comunicação Social","mediaEnem":719.55}, | ||
{"nome":"Glennie Hyatt","cpf":"535.377.996-75","celular":"(36) 12295-4648","nascimento":"1992-03-13T14:32:13.000Z","curso":"Medicina","mediaEnem":437.51}, | ||
{"nome":"Mr. Ericka Schmeler","cpf":"086.883.462-91","celular":"(42) 91668-3807","nascimento":"1992-04-27T01:55:03.000Z","curso":"Letras","mediaEnem":385.61}] | ||
``` | ||
@@ -49,4 +43,7 @@ | ||
Att Type | Exemplo | Valores | ||
Att Type | Example | Generated Values | ||
--------- | ------- | ------ | ||
randExp | /(\(\d{2}\) \d{5}\-\d{4})/ | (31) 55190-5339", (18) 93105-3613, (45) 58872-4444 | ||
enum | "enum:maçã;uva;pera" | maçã, uva, maçã, pera, ... | ||
idAutoIncrement | "idAutoIncrement" | 1, 2, 3, 4, 5, 6, 7, ... | ||
boolean | "boolean" | true, false | ||
@@ -56,12 +53,11 @@ integer:min;max | "integer:20;50" | 11, 40, 23, ... | ||
primeNumber:min;max | "primeNumber:1;10" | 2, 7, 3, ... | ||
date:minyear;maxyear | "date:1990;2000" | 1998-05-24T05:41:16.000Z, ... | ||
date:minyear;maxyear | "date:1990;2000" | 1998-05-24T05:41:16.000Z, ... | ||
latitude | "latitude" | 33.1238, -12.4788, ... | ||
longitude | "longitude" | -100.9198, 177.1068, ... | ||
enum | lista de valores | "enum:maçã;uva;pera" | maçã, uva, pera | ||
id | "id" | -dm-1545847763800-8y6iPo, -dm-1545847763800-FIg6Jx, ... | ||
email | "email" | danny4@gmail.com, paris.mohr@gmail.com, ... | ||
firstName | "firstName" | Liliana, Jessie, Brady, ... | ||
lastName | "lastName" | Wiza, Predovic, Jones, ... | ||
name | "name" | Tobin Wyman, Emilia Bahringer e Eveline Moore | ||
job | "job" | Customer Intranet Producer, Legacy Accounts Specialist, ... | ||
email | "email" | danny4@gmail.com, paris.mohr@gmail.com, ... | ||
firstName | "firstName" | Liliana, Jessie, Brady, ... | ||
lastName | "lastName" | Wiza, Predovic, Jones, ... | ||
name | "name" | Tobin Wyman, Emilia Bahringer e Eveline Moore | ||
job | "job" | Customer Intranet Producer, Legacy Accounts Specialist, ... | ||
word | "word" | temporibus, ratione, reiciendis, ... | ||
@@ -71,2 +67,5 @@ text | "text" | excepturi, Nihil vel impedit repellendus et et repellat officiis., ... | ||
paragraphs | "paragraphs" | Rerum optio quaerat. Doloribus ratione maiores. Deleniti soluta ipsa nobis unde qui enim. Numquam quo minima impedit deleniti quos autem dolor.\n \rIure minima deleniti. Voluptas ut maiores rerum. Sunt dolore magni voluptates tenetur molestiae. Illum voluptatibus numquam error non laboriosam et iusto quae. Quia corrupti fugit. Necessitatibus deserunt porro.\n \rAut in ut omnis. Repudiandae molestias eaque quis in cupiditate. Nulla dicta et asperiores quasi omnis molestiae rerum. | ||
cpf | "cpf" |211.508.653-85, 313.628.781-97, ... | ||
cpf | "cpf" |211.508.653-85, 313.628.781-97, ... | ||
### combine Command | ||
@@ -10,3 +10,3 @@ var ValueGenerator = require('./value-generator'); | ||
Object.keys(objeto).forEach(item => { | ||
if(typeof objeto[item] == 'object'){ | ||
if(typeof objeto[item] == 'object' && objeto[item].constructor != RegExp){ | ||
result[item] = gerarObjeto(objeto[item]); // recursividade | ||
@@ -13,0 +13,0 @@ }else{ |
@@ -6,5 +6,3 @@ var JsonGenerator = require('./json-generator'); | ||
case 'json': | ||
console.log("Generating json..."); | ||
var dataFileName = dataFileName.split('.'); | ||
console.log(dataFileName); | ||
JsonGenerator.setFile(data, dataFileName[0]); | ||
@@ -11,0 +9,0 @@ break; |
module.exports = function(type){ | ||
var regExpParams = /:([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]*;)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]+$/g | ||
var regExpParams = /:([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]*;)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+$/g | ||
var stringParams = type.match(regExpParams) + ''; | ||
@@ -4,0 +4,0 @@ if (stringParams != 'null') { |
@@ -10,3 +10,3 @@ var fs = require('fs'); | ||
var dataJson = JSON.stringify(data); // converte os dados em uma string json | ||
dataJsonWithNewline = dataJson.replaceAll(',',',\n'); | ||
dataJsonWithNewline = dataJson.replaceAll('},{','},\n{'); | ||
fs.writeFile(dataFileName + ".json", dataJsonWithNewline, function(err) { | ||
@@ -17,3 +17,2 @@ if(err) { | ||
} else { | ||
console.log("The file was saved!"); | ||
return true; | ||
@@ -20,0 +19,0 @@ } |
@@ -14,4 +14,4 @@ var getParams = require('../helpers/getParams'); | ||
generate: generate, | ||
regExp: /^enum:([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]*;)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º]+$/ | ||
regExp: /^enum:([\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]*;)*[\w À-ú,\.\-\?&$@#!\+:\(\)\\°\*º\/\[\]]+$/ | ||
}; | ||
//var generateObject = require('./generate-object'); | ||
var AttributeTypes = {}; | ||
let AttributeTypes = {}; | ||
var getName = function(type){ | ||
var regExpTypeName = /^[\w*]*/g | ||
var typeName = type.match(regExpTypeName) + ''; | ||
let getName = type => { | ||
let regExpTypeName = /^[\w*]*/g; | ||
let typeName = type.match(regExpTypeName) + ''; | ||
if (typeName != 'null') { | ||
@@ -14,6 +14,10 @@ return typeName; | ||
var makeAtt = function(type){ | ||
let makeAtt = type => { | ||
var type = type; | ||
var regEx = /^\[\d+\]/; | ||
if(regEx.test(type)){ | ||
if(type.constructor == RegExp){ | ||
let randExp = require(`./types/randExp`); | ||
if(randExp) | ||
return randExp.generate(type); | ||
}else if(regEx.test(type)){ | ||
var array = type.match(regEx)[0]; | ||
@@ -20,0 +24,0 @@ var arrayLength = parseInt(array.slice(1, array.length - 1)); |
var chai = require('chai'); | ||
var BoolType = require('../src/types/bool'); | ||
var BoolType = require('../src/types/boolean'); | ||
@@ -4,0 +4,0 @@ describe('BoolType', function() { |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
56286
65
1008
4
67
8
+ Addedrandexp@^0.5.3
+ Addeddrange@1.1.1(transitive)
+ Addedrandexp@0.5.3(transitive)
+ Addedret@0.2.2(transitive)