I am trying to convert a number into hexadecimal using the number.toString(16) function but it is giving me the error Error Expected 0 arguments, but got 1..
I might be doing something wrong with my types, because I believe it should work.
Here is my code :
type ImageToEncode = {
pixelsAndColors: string[][][];
bounds: string[][][];
paletteIndex: string;
}
task("encodeImage", "Encode an image", async function(taskArgs: ImageToEncode) {
const hexPixelsAndColors = taskArgs.pixelsAndColors
.map((array: string[][]) => {
let firstChar = array[0].toString(16);
let secondChar = array[1].toString(16);
if(firstChar.length < 2) {
firstChar = `0${firstChar}`;
}
if(secondChar.length < 2) {
secondChar =`0${secondChar}`;
}
return [firstChar, secondChar];
})
.map((array: string[]) => array.join(""))
.join("");
const hexBounds = taskArgs.bounds.map(bound => {
let firstChar = bound.toString(16);
if(firstChar.length < 2) {
firstChar = `0${firstChar}`;
}
return firstChar;
}).join("");
const hexData = `0x${taskArgs.paletteIndex}${hexBounds}${hexPixelsAndColors}`
console.log(hexData);
return hexData;
});
For information can be interpreted like a function.