tf2-item-format
Version:
Format's TF2 items like backpack.tf does
71 lines • 2.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const getKillstreak_1 = __importDefault(require("../../shared/getKillstreak"));
/**
* Finds out which usable item it is
* and its type
* `output` or `target`
* @param {string} name
* @return {Object}
*/
function default_1(name) {
// TODO: add series to itemNumber.
// For chemistry sets the quality is predefined
if (isStrangifierChemistrySet(name)) {
return {
target: name.replace(' Strangifier Chemistry Set', ''),
output: 'Strangifier',
outputQuality: 'Unique',
};
}
if (isChemistrySet(name)) {
return {
output: name
.replace(' Chemistry Set', '')
.replace("Collector's ", ''),
outputQuality: "Collector's",
};
}
const item = getItemIfTarget(name);
if (item) {
return {
target: name
.replace(` ${item}`, '')
.replace(`${(0, getKillstreak_1.default)(name)} `, '')
// Incase its uncraftable
.replace('Non-Craftable ', '')
// For Unusualifiers
.replace('Unusual ', ''),
};
}
return null;
}
function isStrangifierChemistrySet(name) {
return name.includes(' Strangifier Chemistry Set');
}
const KIT_EXCEPTIONS = [
"Killer's Kit",
'Coffin Kit',
'Summer Starter Kit',
"Chiromancer's Kit",
];
function getItemIfTarget(name) {
const match = name.match(/ (Kit Fabricator|Strangifier|Unusualifier)/);
if (match) {
return match[1];
}
if (!name.includes(' Kit')) {
return;
}
return KIT_EXCEPTIONS.some((exception) => name.includes(exception))
? undefined
: 'Kit';
}
function isChemistrySet(name) {
return name.includes(' Chemistry Set');
}
//# sourceMappingURL=getUsableItem.js.map