* * @param {string} tag * @returns
(tag)
| 30 | * @returns |
| 31 | */ |
| 32 | function parseLocation(tag) { |
| 33 | let _tag = String(tag || ''); |
| 34 | const ctx = { |
| 35 | tag: _tag, |
| 36 | isOffline: false, |
| 37 | isPrivate: false, |
| 38 | isTraveling: false, |
| 39 | isRealInstance: false, |
| 40 | worldId: '', |
| 41 | instanceId: '', |
| 42 | instanceName: '', |
| 43 | accessType: '', |
| 44 | accessTypeName: '', |
| 45 | region: '', |
| 46 | shortName: '', |
| 47 | userId: null, |
| 48 | hiddenId: null, |
| 49 | privateId: null, |
| 50 | friendsId: null, |
| 51 | groupId: null, |
| 52 | groupAccessType: null, |
| 53 | canRequestInvite: false, |
| 54 | strict: false, |
| 55 | ageGate: false |
| 56 | }; |
| 57 | if (_tag === 'offline' || _tag === 'offline:offline') { |
| 58 | ctx.isOffline = true; |
| 59 | } else if (_tag === 'private' || _tag === 'private:private') { |
| 60 | ctx.isPrivate = true; |
| 61 | } else if (_tag === 'traveling' || _tag === 'traveling:traveling') { |
| 62 | ctx.isTraveling = true; |
| 63 | } else if (tag && !_tag.startsWith('local')) { |
| 64 | ctx.isRealInstance = true; |
| 65 | const sep = _tag.indexOf(':'); |
| 66 | // technically not part of instance id, but might be there when coping id from url so why not support it |
| 67 | const shortNameQualifier = '&shortName='; |
| 68 | const shortNameIndex = _tag.indexOf(shortNameQualifier); |
| 69 | if (shortNameIndex >= 0) { |
| 70 | ctx.shortName = _tag.substr( |
| 71 | shortNameIndex + shortNameQualifier.length |
| 72 | ); |
| 73 | _tag = _tag.substr(0, shortNameIndex); |
| 74 | } |
| 75 | if (sep >= 0) { |
| 76 | ctx.worldId = _tag.substr(0, sep); |
| 77 | ctx.instanceId = _tag.substr(sep + 1); |
| 78 | ctx.instanceId.split('~').forEach((s, i) => { |
| 79 | if (i) { |
| 80 | const A = s.indexOf('('); |
| 81 | const Z = A >= 0 ? s.lastIndexOf(')') : -1; |
| 82 | const key = Z >= 0 ? s.substr(0, A) : s; |
| 83 | const value = A < Z ? s.substr(A + 1, Z - A - 1) : ''; |
| 84 | if (key === 'hidden') { |
| 85 | ctx.hiddenId = value; |
| 86 | } else if (key === 'private') { |
| 87 | ctx.privateId = value; |
| 88 | } else if (key === 'friends') { |
| 89 | ctx.friendsId = value; |
no outgoing calls
no test coverage detected