We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maybe I need a break from coding, but I really don't get why I can't retrieve the value from the function...
Can anyone please tell me what I'm doing wrong?
const parseRTF = require("rtf-parser"); let string = `{\\rtf1\\ansi\\deff0\\nouicompat{\\ etc...}`; function convertRTFtoPlainText(string) { parseRTF.string(string, (err, doc) => { let result = ""; doc.content.forEach((item) => { if (item.content) { item.content.forEach((span) => { result += span.value; }); } }); console.log(result); // <-------- Shows the converted string return result.trim(); }); } let value = convertRTFtoPlainText(string); console.log(value); // <-------- undefined
The text was updated successfully, but these errors were encountered:
You should use Promise here
const parseRTF = require("rtf-parser"); function convertRTFtoPlainText(str) { return new Promise( function(resolve, reject) { parseRTF.string( str, function (error, doc) { if (error) { return reject(error); } let result = ""; doc.content.forEach((item) => { if (item.content) { item.content.forEach((span) => { result += span.value; }); } }); resolve(result.trim()); } ); } ); } const string = `{\\rtf1\\ansi\\deff0\\nouicompat{\\ etc...}`; convertRTFtoPlainText(string).then( function (value) { console.log('convertRTFtoPlainText = ' + value); } ).catch( function (error) { console.error('Error in convertRTFtoPlainText', error) } );
Sorry, something went wrong.
No branches or pull requests
Maybe I need a break from coding, but I really don't get why I can't retrieve the value from the function...
Can anyone please tell me what I'm doing wrong?
The text was updated successfully, but these errors were encountered: