UNPKG

@mann-conomy/tf-war-paints

Version:

A static Node.js wrapper for Team Fortress 2's many War Paints.

56 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllAttributesOrThrow = getAllAttributesOrThrow; exports.evaluate = evaluate; exports.find = find; exports.translate = translate; const enums_1 = require("../resources/enums"); const utils_1 = require("./utils"); function createWarPaintWithDefaults(warpaint) { return { id: warpaint.id || enums_1.InvalidWarPaint.Id, name: warpaint.name || enums_1.InvalidWarPaint.Name, language: warpaint.language || enums_1.LanguageTranslation.English }; } function getAllAttributesOrThrow(warpaints, language) { const attributes = warpaints[language]; if (!Array.isArray(attributes)) { throw new RangeError("No War Paints were found matching the provided language code."); } return attributes; } function evaluate(warpaints, warpaint, strict) { const paint = createWarPaintWithDefaults(warpaint); const attributes = getAllAttributesOrThrow(warpaints, paint.language); if (strict) { return attributes.some(attribute => (0, utils_1.compareByIdAndName)(attribute, paint)); } return attributes.some(attribute => (0, utils_1.compareByIdOrName)(attribute, paint)); } function find(warpaints, warpaint, strict) { const paint = createWarPaintWithDefaults(warpaint); const attributes = getAllAttributesOrThrow(warpaints, paint.language); if (strict) { const attribute = attributes.find(attribute => (0, utils_1.compareByIdAndName)(attribute, paint)); if (attribute !== undefined) { return attribute; } throw new RangeError("No War Paint was found with the specified id and name."); } const attribute = attributes.find(attribute => (0, utils_1.compareByIdOrName)(attribute, paint)); if (attribute !== undefined) { return attribute; } throw new RangeError("No War Paint was found with the specified id or name."); } function translate(warpaints, warpaint, language, strict) { const paint = find(warpaints, warpaint, strict); const attributes = getAllAttributesOrThrow(warpaints, language); const attribute = attributes.find(attribute => (0, utils_1.compareById)(attribute, paint.id)); if (attribute !== undefined) { return attribute; } throw new Error("No translation exists for this War Paint."); } //# sourceMappingURL=static.js.map