Skip to content

Instantly share code, notes, and snippets.

@Gwash3189
Created November 20, 2015 12:32
Show Gist options
  • Save Gwash3189/045272e71b1a60385014 to your computer and use it in GitHub Desktop.
Save Gwash3189/045272e71b1a60385014 to your computer and use it in GitHub Desktop.
const src = `
var a = 1;
var b:string = '123'
interface User {
name: string
}
`;
const getDataBetweenChars = (start, end, data) => {
const lines = cleanArray(data.split('\n'))
let flag = false;
let newData = '';
cleanArray(lines.map(line => {
if (contains(line, start)) {
flag = true
} else if (contains(line, end)) {
flag = false
}
newData = flag
? newData + line
: newData;
}));
return newData
.replace(start, '')
.replace(stop, '');
}
const contains = (s, c) => {
return s.indexOf(c) > -1
}
const cleanArray = (a) => {
return a.filter(x => x)
}
console.log(getDataBetweenChars('interface', '}', src));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment