Aliased / pixelated rasterization in HTML Canvas

Is there any way to force 2d canvas commands to draw pixelated (without anti-aliasing) in a way that's computationally efficient? E.g. I want to say:

ctx.beginPath();

ctx.moveTo(0,0);

ctx.lineTo(100,100);

ctx.stroke();

And I want that to draw a line that is pixelated e.g.:

https://preview.redd.it/a1sfh75yysoh1.png?width=504&format=png&auto=webp&s=98048dced227ac1b82fe6b00c25287c13a67e908

submitted by /u/Glum_Mud9703
[link] [留言]