@technobuddha/library
Version:
A large library of useful functions
39 lines (38 loc) • 1.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortOrder = void 0;
var clean_1 = __importDefault(require("../clean"));
/**
* Convert a string into a sortable string
*
* @remarks for example "The Beatles" becomes "Beatles, The"
* @param input string to convert
* @param __namedParameters see {@link Options}
* @return sortable string
*/
function sortOrder(input, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.ignoreQuotes, ignoreQuotes = _c === void 0 ? true : _c, _d = _b.moveArticles, moveArticles = _d === void 0 ? true : _d;
input = clean_1.default(input);
if (ignoreQuotes && input.startsWith('"')) {
var quote = input.slice(0, 1);
input = input.slice(1);
var index = input.indexOf(quote, 1);
if (index >= 0)
input = input.slice(0, index) + input.slice(index + 1);
}
var lc = input.toLowerCase();
if (moveArticles) {
if (lc.startsWith('a '))
input = input.slice(2) + ", " + input.slice(0, 1);
else if (lc.startsWith('an '))
input = input.slice(3) + ", " + input.slice(0, 2);
else if (lc.startsWith('the '))
input = input.slice(4) + ", " + input.slice(0, 3);
}
return input;
}
exports.sortOrder = sortOrder;
exports.default = sortOrder;