toHex polyfill
This commit is contained in:
22
src/pdf/uint8ArrayToHexPolyfill.ts
Normal file
22
src/pdf/uint8ArrayToHexPolyfill.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
type Uint8ArrayWithToHex = Uint8Array & {
|
||||
toHex?: () => string;
|
||||
};
|
||||
|
||||
const uint8ArrayPrototype = Uint8Array.prototype as Uint8ArrayWithToHex;
|
||||
|
||||
if (typeof uint8ArrayPrototype.toHex !== 'function') {
|
||||
Object.defineProperty(Uint8Array.prototype, 'toHex', {
|
||||
value: function toHex(this: Uint8Array): string {
|
||||
const hex = new Array<string>(this.length);
|
||||
|
||||
for (let index = 0; index < this.length; index += 1) {
|
||||
const value = this[index].toString(16);
|
||||
hex[index] = value.length === 1 ? `0${value}` : value;
|
||||
}
|
||||
|
||||
return hex.join('');
|
||||
},
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user