let sPlain = 'plain text'
, sHtml = 'text <i>with tags</i>'
, wrapped_sp = `<div>${sPlain}</div>`
, wrapped_sh = `<div>${sHtml}</div>`
, w2t_sp = $(wrapped_sp).text()
, w2t_sh = $(wrapped_sh).text()
, isplain_sp = ( w2t_sp == sPlain )
, isplain_sh = ( w2t_sh == sHtml )
console.log( "%s is %stext/plain", sPlain, isplain_sp ? "" : "NOT " );
console.log( "%s is %stext/plain", sHtml, isplain_sh ? "" : "NOT " );
As answer to the original question specifically:
let is_bufferText_plain = ( $(`<div>${bufferText}</div>`).text() == bufferText );
if( is_bufferText_plain ){
// do whatever is required if the bufferText content is text/plain
}else{
// do whatever is required if the bufferText content is text/html
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…