This commit is contained in:
Maciej Caderek
2022-02-14 00:00:41 +01:00
parent 6274236ac7
commit e0b79a7071
26 changed files with 608 additions and 358 deletions

View File

@@ -0,0 +1,27 @@
import { decompressPGN } from "../game/PGNHelpers";
const HEADER_REGEX = /^#v\d+\/(pgn|fen)\//;
const extractUrlData = () => {
const hash = window.location.hash;
if (!HEADER_REGEX.test(hash)) {
return {
pgn: "",
fen: "",
};
}
const [rawVersion, format, ...chunks] = hash.split("/");
const version = Number((rawVersion.match(/\d+/g) ?? [])[0]);
const data = chunks.join("/");
return {
version,
pgn: format === "pgn" ? decompressPGN(data) : "",
fen: format === "fen" ? decodeURI(data) : "",
};
};
export default extractUrlData;