--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - capwords('kevin van zonneveld') - capwords('HELLO WORLD') returns: - '''Kevin Van Zonneveld''' - '''HELLO WORLD''' dependencies: [] authors: original by: - Jonas Raoni Soares Silva (https://www.jsfromhell.com) improved by: - Waldo Malqui Silva (https://waldo.malqui.info) - Robin - Kevin van Zonneveld (https://kvz.io) bugfixed by: - Onno Marsman (https://twitter.com/onnomarsman) input by: - James (https://www.james-bell.co.uk/) notes: [] parityVerified: null isTypescript: true type: function layout: function title: Python's string.capwords in TypeScript description: >- Here's what our current TypeScript equivalent to Python's string.capwords looks like. function: capwords category: string language: python permalink: python/string/capwords/ alias: - /functions/python/capwords/ - /functions/string/capwords/ - /python/capwords/ ---
{% codeblock lang:typescript %}export function capwords(str: string): string { // discuss at: https://locutus.io/python/capwords/ // original by: Jonas Raoni Soares Silva (https://www.jsfromhell.com) // improved by: Waldo Malqui Silva (https://waldo.malqui.info) // improved by: Robin // improved by: Kevin van Zonneveld (https://kvz.io) // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) // input by: James (https://www.james-bell.co.uk/) // example 1: capwords('kevin van zonneveld') // returns 1: 'Kevin Van Zonneveld' // example 2: capwords('HELLO WORLD') // returns 2: 'HELLO WORLD' const pattern = /^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g return (str + '').replace(pattern, function ($1) { return $1.toUpperCase() }) } {% endcodeblock %}