Skip to content

Instantly share code, notes, and snippets.

@davidsonsns
Created July 17, 2017 16:07
Show Gist options
  • Save davidsonsns/a3607c5dac603234324a8cd66feb3947 to your computer and use it in GitHub Desktop.
Save davidsonsns/a3607c5dac603234324a8cd66feb3947 to your computer and use it in GitHub Desktop.
function draftToText(obj) {
return new Promise((resolve, reject) => {
try {
const draftObj = typeof obj === 'string' ? JSON.parse(obj) : obj;
const completText = [];
for (let index = 0; index < draftObj.blocks.length; index++) {
completText.push(obj.blocks[index].text.trim());
}
resolve(completText.join(' '));
} catch (error) {
reject();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment