tf2-item-format
Version:
Format's TF2 items like backpack.tf does
41 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = isUniqueHat;
exports.isUniqueHatException = isUniqueHatException;
exports.getUniqueHatExceptions = getUniqueHatExceptions;
exports.findUniqueHatExceptions = findUniqueHatExceptions;
const schemaCache_1 = require("./schemaCache");
const SCHEMA_CACHE_UNIQUE_HAT_EXCEPTIONS_KEY = 'uniqueHatExceptions';
/**
* Signalizes if `The` is at the start of name.
* Only happens to hats with unique quality.
*/
function isUniqueHat(schema, name, attributes) {
if (!name.startsWith('The ')) {
return false;
}
return !isUniqueHatException(schema, name, !(attributes === null || attributes === void 0 ? void 0 : attributes.itemNumber));
}
function isUniqueHatException(schema, name, exact) {
const exceptions = getUniqueHatExceptions(schema);
if (!exact) {
return exceptions.some((item) => name.startsWith(item));
}
return exceptions.includes(name);
}
function getUniqueHatExceptions(schema) {
let exceptions = schemaCache_1.cache.get(schema, SCHEMA_CACHE_UNIQUE_HAT_EXCEPTIONS_KEY);
if (exceptions) {
return exceptions;
}
exceptions = findUniqueHatExceptions(schema);
schemaCache_1.cache.save(schema, SCHEMA_CACHE_UNIQUE_HAT_EXCEPTIONS_KEY, exceptions);
return exceptions;
}
function findUniqueHatExceptions(schema) {
const items = schema.getItems();
return items
.filter((item) => item.item_name.startsWith('The '))
.map((item) => item.item_name);
}
//# sourceMappingURL=isUniqueHat.js.map