Created
September 12, 2017 15:27
-
-
Save bitifet/6dc9036cbdeefe89ef1de3c63bceca63 to your computer and use it in GitHub Desktop.
NodeJS Ensaimeitor Draft.
This file contains hidden or 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
| // Node Ensaimeitor Draft. | |
| // Thanks to http://ensaimeitor.apsl.net/ | |
| "use strict"; | |
| const srvHost = "ensaimeitor.apsl.net"; | |
| const srvPort = 80; | |
| const index = {//{{{ | |
| fiscal: "NIF's", | |
| cif: "CIF's", | |
| empresas: "Empresas", | |
| bancos: "Nº Cuenta Bancaria", | |
| gen_visa: "Números Visa", | |
| gen_mastercard: "Números Mastercard", | |
| gen_amex: "Números Amex", | |
| personas: "Nombres Personas", | |
| country: "Nombres Paises", | |
| provincias: "Nombres Provincias", | |
| cod_postal: "Códigos Postales", | |
| direccion: "Direcciones Postales", | |
| spanish_phone: "Números de Teléfono", | |
| gen_urls: "Sítios Web", | |
| gen_emails: "Direcciones E-mail", | |
| chomsky: "Texto Chomsky", | |
| li_sentence: "Sentencias Lorem Ipsum", | |
| li_paragraph: "Párrafos Lorem Ipsum", | |
| gpw: "Passwords", | |
| // perfil: "Perfiles", // Doesn't accept 'num' spec. | |
| };//}}} | |
| var http = require("http"); // Native. | |
| function get(what, count) {//{{{ | |
| if (! count) count = 10; | |
| return new Promise(function ensGetter(resolve, reject) { | |
| http.get( | |
| { | |
| hostname: srvHost, | |
| path: "/"+what | |
| + "/"+count // Actually ignored | |
| + "/?format=json" | |
| + "&num="+count | |
| , | |
| port: srvPort | |
| } | |
| , function (res) { | |
| var data = ""; | |
| res.on('data', (chunk) => { | |
| data += chunk; | |
| }); | |
| res.on('end', foo=>resolve(JSON.parse(data).codigo)); | |
| res.on('error', reject); | |
| } | |
| ); | |
| }); | |
| };//}}} | |
| function ensaimate(what, count) {//{{{ | |
| if (! (what instanceof Array)) what = what.split(","); | |
| what = what.map(x=>x.trim()); | |
| return Promise.all( | |
| what.map(x=>get(x,count)) | |
| ).then(function(data){ | |
| var result = []; | |
| for (var i=0; i<count; i++) { | |
| result[i] = {}; | |
| for (var j=0; j<what.length; j++) { | |
| result[i][what[j]] = data[j][i]; | |
| }; | |
| }; | |
| return result; | |
| }); | |
| };//}}} | |
| ensaimate( | |
| "fiscal, empresas, personas, country, direccion" | |
| // Object.keys(index) | |
| , 10 | |
| ) | |
| .then(x=>console.log(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment