* Creates string preview of given Chain object. * @param {Chain} content * @return {string}
(content)
| 37 | * @return {string} |
| 38 | */ |
| 39 | static preview (content) { |
| 40 | if (!content.needsTextEncoding()) { |
| 41 | // truncate text to preview length |
| 42 | return content.truncate(previewLength) |
| 43 | } |
| 44 | |
| 45 | // create hex byte preview |
| 46 | const previewBytes = content.getBytes().slice(0, previewLength / 2) |
| 47 | const preview = ByteEncoder.hexStringFromBytes(previewBytes) |
| 48 | return content.getBytes().length > previewLength / 2 |
| 49 | ? preview + '…' |
| 50 | : preview |
| 51 | } |
| 52 | } |