UNPKG

640 BJavaScriptView Raw
1exports = module.exports.trim = trim;
2function trim(string) {
3 return string.replace(/^\s*|\s*$/g, '')
4}
5
6exports = module.exports.slugify = slugify;
7function slugify(text) {
8 text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
9 text = text.replace(/-/gi, "_");
10 text = text.replace(/\s/gi, "_");
11 return text;
12}
13
14exports = module.exports.parse = function parse(data) {
15 var ret = {};
16 var lines = data.split(/\r\n|\r|\n/g);
17 for (var i=0; i<lines.length-2; i++) {
18 var line = lines[i];
19 var tup = line.split(': ');
20 if (tup.length === 2) {
21 ret[slugify(tup[0]).toLowerCase()] = trim(tup[1]);
22 }
23 }
24 return ret;
25
26}