diff options
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/title/lib/index.js')
-rw-r--r-- | bin/wiki/ImportarDesdeURL/node_modules/title/lib/index.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/title/lib/index.js b/bin/wiki/ImportarDesdeURL/node_modules/title/lib/index.js new file mode 100644 index 00000000..74977d9f --- /dev/null +++ b/bin/wiki/ImportarDesdeURL/node_modules/title/lib/index.js @@ -0,0 +1,51 @@ +// Utilities +const lowerCase = require('./lower-case') +const specials = require('./specials') + +const regex = /(?:(?:(\s?(?:^|[.\(\)!?;:"-])\s*)(\w))|(\w))(\w*[’']*\w*)/g + +const convertToRegExp = specials => specials.map(s => [new RegExp(`\\b${s}\\b`, 'gi'), s]) + +function parseMatch(match) { + const firstCharacter = match[0] + + // test first character + if (/\s/.test(firstCharacter)) { + // if whitespace - trim and return + return match.substr(1) + } + if (/[\(\)]/.test(firstCharacter)) { + // if parens - this shouldn't be replaced + return null + } + + return match +} + +module.exports = (str, options = {}) => { + str = str.toLowerCase().replace(regex, (m, lead = '', forced, lower, rest) => { + const parsedMatch = parseMatch(m) + if (!parsedMatch) { + return m + } + if (!forced) { + const fullLower = lower + rest + + if (lowerCase.has(fullLower)) { + return parsedMatch + } + } + + return lead + (lower || forced).toUpperCase() + rest + }) + + const customSpecials = options.special || [] + const replace = [...specials, ...customSpecials] + const replaceRegExp = convertToRegExp(replace) + + replaceRegExp.forEach(([pattern, s]) => { + str = str.replace(pattern, s) + }) + + return str +} |