Skip to content

Commit

Permalink
testing husky pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Jan 7, 2024
1 parent 7336197 commit 20b2c4a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
}
},
"lint-staged": {
"*.{js,ts}": [
"src/**/*.{js,ts}": [
"prettier --write",
"eslint . --ext .ts --fix",
"npm run lint:fix",
"git add"
]
}
Expand Down
77 changes: 39 additions & 38 deletions src/js/jagex2/util/JsUtil.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
import {decompress} from '../../vendor/bz2.js';

export const sleep = async (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms));
export const downloadUrl = async (url: string): Promise<Uint8Array> => new Uint8Array(await (await fetch(url)).arrayBuffer());
export const downloadUrl = async (url: string): Promise<Uint8Array> =>
new Uint8Array(await (await fetch(url)).arrayBuffer());
export const downloadText = async (url: string): Promise<string> => (await fetch(url)).text();

export const decompressBz2 = (data: Uint8Array, addMagic: boolean = true, prepend: boolean = true): Uint8Array => {
if (addMagic) {
const magic = Uint8Array.from(['B'.charCodeAt(0), 'Z'.charCodeAt(0), 'h'.charCodeAt(0), '1'.charCodeAt(0)]);
if (addMagic) {
const magic = Uint8Array.from(['B'.charCodeAt(0), 'Z'.charCodeAt(0), 'h'.charCodeAt(0), '1'.charCodeAt(0)]);

if (prepend) {
const temp = data;
data = new Uint8Array(magic.length + data.length);
data.set(temp, magic.length);
}

data.set(magic, 0);
if (prepend) {
const temp = data;
data = new Uint8Array(magic.length + data.length);
data.set(temp, magic.length);
}

return decompress(data);
data.set(magic, 0);
}

return decompress(data);
};

export const decodeJpeg = async (data: Uint8Array | null): Promise<ImageData> => {
if (!data) {
throw new Error("Input jpeg data was null!");
}
if (data[0] !== 0xFF) {
// fix invalid JPEG header
data[0] = 0xFF;
}

// create img element
const img = document.createElement('img');
img.src = 'data:image/jpeg;base64,' + btoa(String.fromCharCode(...data));

// wait for img to load
await new Promise(resolve => img.onload = resolve);

// get imagedata from img element
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d');
if (!ctx) {
throw new Error('Canvas 2d not found!!!!!!!!');
}
ctx.drawImage(img, 0, 0);
return ctx.getImageData(0, 0, canvas.width, canvas.height);
if (!data) {
throw new Error('Input jpeg data was null!');
}
if (data[0] !== 0xff) {
// fix invalid JPEG header
data[0] = 0xff;
}

// create img element
const img = document.createElement('img');
img.src = 'data:image/jpeg;base64,' + btoa(String.fromCharCode(...data));

// wait for img to load
await new Promise(resolve => (img.onload = resolve));

// get imagedata from img element
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d');
if (!ctx) {
throw new Error('Canvas 2d not found!!!!!!!!');
}
ctx.drawImage(img, 0, 0);
return ctx.getImageData(0, 0, canvas.width, canvas.height);
};

export const arraycopy = (src: Uint32Array, srcPos: number, dst: Uint32Array, dstPos: number, length: number): void => {
while (length--) dst[dstPos++] = src[srcPos++];
}
while (length--) dst[dstPos++] = src[srcPos++];
};

0 comments on commit 20b2c4a

Please sign in to comment.