Created
July 17, 2017 16:07
-
-
Save davidsonsns/a3607c5dac603234324a8cd66feb3947 to your computer and use it in GitHub Desktop.
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
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