UNPKG

tf2-item-format

Version:
98 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const KILLSTREAKER_SHEEN_REGEX = /^\(Killstreaker: ([a-zA-Z0-9 \-]+), Sheen: ([a-zA-Z0-9 \-]+)\)$/; /** * Handles killstreak actions */ class Killstreak { get killstreak() { return this.value; } constructor(schema) { this.schema = schema; } set killstreak(value) { if (this.schema.getKillstreakEnum(value) < this.schema.getKillstreakEnum(this.killstreak)) return; this.value = value; } static isKillstreakerSheenDescription(description) { return KILLSTREAKER_SHEEN_REGEX.test(description.value); } /** * Checks if description includes killstreaker * Killstreaker is an `effect` from killstreak * @param {object} description * @return {boolean} */ static isKillstreaker(description) { return (description.value.startsWith('Killstreaker: ') && description.color === '7ea9d1'); } /** * Checks if description includes sheen * @param {object} description * @return {boolean} */ static isSheen(description) { if (description.value.startsWith('(Sheen: ') && description.value.endsWith(')')) { return true; } return (description.value.startsWith('Sheen: ') && description.color === '7ea9d1'); } /** * Checks if item is killstreak from description * @param {object} description * @return {boolean} */ static isKillstreak(description) { return (description.value === 'Killstreaks Active' && description.color === '7ea9d1'); } setKillstreakerSheen(description) { const match = description.value.match(KILLSTREAKER_SHEEN_REGEX); if (match == null) { throw new Error("Wrongly matched killstreaker for econ item, report this incident to github."); } const [_, killstreaker, sheen] = match; this.sheen = sheen; this.killstreaker = killstreaker; this.killstreak = 'Professional Killstreak'; } /** * Sets killstreaker from description * @param {object} description * @return {string} */ setKillstreaker(description) { this.killstreaker = description.value.replace('Killstreaker: ', ''); this.killstreak = 'Professional Killstreak'; } /** * Sets sheen from description * @param {object} description * @return {string} */ setSheen(description) { if (description.value.startsWith('(')) { this.sheen = description.value .replace(/^\(Sheen: /, '') .replace(/\)$/, ''); } else { this.sheen = description.value.replace('Sheen: ', ''); } this.killstreak = 'Specialized Killstreak'; } /** * Sets killstreak according to other attrs. * @param {object} attributes */ setKillstreak() { this.killstreak = 'Killstreak'; } } exports.default = Killstreak; //# sourceMappingURL=Killstreak.js.map