Created
September 19, 2016 15:44
-
-
Save iglosiggio/ac429e02f4021c99bc6839d38c21318e to your computer and use it in GitHub Desktop.
Parsea un Package de debian (se puede mejorar pero al menos funca :P)
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
// Se puede probar con http://repo.huayra.conectarigualdad.gob.ar/huayra/dists/unstable/main/binary-amd64/Packages | |
function parse_package(text) { | |
'use strict'; | |
const regex = { | |
field: /([^:\n]+): ([^\n]+)\n((:? [^\n]*\n)*)/g, | |
package: /(:?[^\n]+\n)+\n/g | |
} | |
var result = {}; | |
var pkg; | |
var field; | |
while(pkg = regex.package.exec(packagelist)) { | |
let obj = {}; | |
pkg = pkg[0]; | |
while(field = regex.field.exec(pkg)) { | |
obj[field[1]] = field[3] ? field[2] + field[3] : field[2]; | |
} | |
result[obj["Package"]] = obj; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment