1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-17 22:41:29 +00:00
Files
homebrewery/server/utils.js
Scott Tolksdorf 1173af5803 'Created
2017-01-22 12:44:38 -05:00

23 lines
473 B
JavaScript

const _ = require('lodash');
module.exports = {
getGoodBrewTitle : (text) => {
const titlePos = text.indexOf('# ');
if(titlePos !== -1){
const ending = text.indexOf('\n', titlePos);
return text.substring(titlePos + 2, ending);
}else{
return _.find(text.split('\n'), (line)=>{
return line;
});
}
},
replaceByMap : (text, mapping) => {
return _.reduce(mapping, (r, search, replace) => {
return r.split(search).join(replace)
}, text)
}
}