PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / utils / dash-case-to-title / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/utils/dash-case-to-title/index.js

26 lines 577 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Dash case to Title case.
3 *
4 * dashCaseToTitle('user-id') => "User Id"
5 * dashCaseToTitle('wait-a-moment') => "Wait A Moment"
6 *
7 * https://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
8 *
9 * @param {string} str - dash-cased string.
10 * @return {string} - new title-cased string.
11 */
12 export default function dashCaseToTitle(str) {
13 if (typeof str !== 'string') {
14 return str;
15 }
16
17 return str
18 .split(/[.,/ \-_]/)
19 .map((word) =>
20 word && word.length
21 ? word.replace(word[0], word[0].toUpperCase())
22 : word
23 )
24 .join(' ');
25 }
26