csformat
Version:
The only package you need to format CS2 item queries into the Steam Market format
37 lines (36 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFormatOptions = exports.toTitleCase = exports.wordToTitleCase = void 0;
const wordToTitleCase = (word) => {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
};
exports.wordToTitleCase = wordToTitleCase;
const toTitleCase = (str) => {
const words = [];
// Add words and hyphenated words to array
str.split(' ').forEach((word) => {
let hasHyphen = false;
// Check for hyphenated words in the string
word.split('-').forEach((word) => {
words.push(word.toLowerCase());
hasHyphen = true;
});
if (!hasHyphen)
words.push(word);
});
return words.map(exports.wordToTitleCase).join(' ');
};
exports.toTitleCase = toTitleCase;
function getFormatOptions(format) {
// Possible format combinations
// Remove duplicates
return [
...new Set([
format.split('-').join(' '),
format.split(' ').join('-'),
format.split(' ').join(''),
format,
]),
];
}
exports.getFormatOptions = getFormatOptions;