/chat-codes

Encode and decode guildwars2 chat codes

Primary LanguageTypeScriptMIT LicenseMIT

chat-codes

Build Status Coverage Status

Encode and decode Guild Wars2 chat codes

This is part of gw2efficiency. Please report all issues in the central repository.

Install

npm install gw2e-chat-codes

This module can be used for Node.js as well as browsers using Browserify.

Usage

const { encode, decode } = require('gw2e-chat-codes')

// Encode a type and id as a chat code
// Valid types are item, map, skill, trait, recipe, skin, outfit & objective
let encodedSkill = encode('skill', 5842)
// -> '[&BtIWAAA=]'

// You can pass an object as second parameter to also encode quantity, skin or upgrades
let encodedItem = encode('item', {id: 46762, quantity: 10, skin: 5807, upgrades: [24554, 24615]})
// -> '[&AgGqtgDgrxYAAOpfAAAnYAAA]'

// Decode a chat code into type and id
let decodedCode = decode('[&BtIWAAA=]')
// -> {type: 'skin', id: 5842}

Tests

npm test

Licence

MIT

Big thanks to codemasher & poke, who wrote this algorithm in PHP, and darthmaim who wrote most of the build template link code.