2020-05-22 00:35:45 +07:00
|
|
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
|
|
|
|
@Pipe({
|
|
|
|
name: 'hex2ascii'
|
|
|
|
})
|
|
|
|
export class Hex2asciiPipe implements PipeTransform {
|
|
|
|
|
|
|
|
transform(hex: string): string {
|
2020-06-06 23:50:08 +07:00
|
|
|
const opPush = hex.split(' ').filter((_, i, a) => i > 0 && /^OP_PUSH/.test(a[i - 1]));
|
|
|
|
|
|
|
|
if (opPush[0]) {
|
|
|
|
hex = opPush[0];
|
|
|
|
}
|
|
|
|
|
2020-05-22 00:35:45 +07:00
|
|
|
if (!hex) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
let str = '';
|
|
|
|
for (let i = 0; i < hex.length; i += 2) {
|
|
|
|
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|