This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
admin-panel/graphql-types/node_modules/title-case/dist.es2015/index.js

30 lines
1.2 KiB
JavaScript

var SMALL_WORDS = /\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\.?|versus|via|when|with|without|yet)\b/i;
var TOKENS = /[^\s:–—-]+|./g;
var WHITESPACE = /\s/;
var IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
var ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;
export function titleCase(input) {
var result = "";
var m;
// tslint:disable-next-line
while ((m = TOKENS.exec(input)) !== null) {
var token = m[0], index = m.index;
if (
// Ignore already capitalized words.
!IS_MANUAL_CASE.test(token) &&
// Ignore small words except at beginning or end.
(!SMALL_WORDS.test(token) ||
index === 0 ||
index + token.length === input.length) &&
// Ignore URLs.
(input.charAt(index + token.length) !== ":" ||
WHITESPACE.test(input.charAt(index + token.length + 1)))) {
// Find and uppercase first word character, skips over *modifiers*.
result += token.replace(ALPHANUMERIC_PATTERN, function (m) { return m.toUpperCase(); });
continue;
}
result += token;
}
return result;
}
//# sourceMappingURL=index.js.map