MCPcopy Create free account
hub / github.com/melonjs/melonJS / getUriFragment

Function getUriFragment

packages/melonjs/src/utils/utils.ts:61–103  ·  view source on GitHub ↗
(url?: string)

Source from the content-addressed store, hash-verified

59 * console.log(UriFragment["mytag"]); //> "value"
60 */
61export function getUriFragment(url?: string) {
62 const hash: Record<string, string | boolean> = {};
63
64 if (typeof url === "undefined") {
65 if (typeof globalThis.document !== "undefined") {
66 const location = globalThis.document.location;
67
68 if (location && location.hash) {
69 url = location.hash;
70 } else {
71 // No "document.location" exist for Wechat mini game platform.
72 return hash;
73 }
74 } else {
75 // "document" undefined on node.js
76 return hash;
77 }
78 } else {
79 // never cache if a url is passed as parameter
80 const index = url.indexOf("#");
81 if (index !== -1) {
82 url = url.slice(index, url.length);
83 } else {
84 return hash;
85 }
86 }
87
88 // parse the url
89 url
90 .slice(1)
91 .split("&")
92 .filter((value) => {
93 return value !== "";
94 })
95 .forEach((value) => {
96 const kv = value.split("=");
97 const k = kv.shift()!;
98 const v = kv.join("=");
99 hash[k] = v || true;
100 });
101
102 return hash;
103}
104
105/**
106 * reset the GUID Base Name

Callers 2

initMethod · 0.90
bootFunction · 0.90

Calls 4

sliceMethod · 0.80
splitMethod · 0.65
forEachMethod · 0.45
shiftMethod · 0.45

Tested by

no test coverage detected