diff --git a/String/Capitalize.js b/String/Capitalize.js new file mode 100644 index 0000000000..1a3c9bae6f --- /dev/null +++ b/String/Capitalize.js @@ -0,0 +1,17 @@ +/** + * @function capitalize + * @description Will convert the first character of the string to uppercase + * @param {String} str - The input string + * @returns {String} Capitalized string + * @example capitalize("hello") => Hello + * @example capitalize("_ello") => _ello + */ +const capitalize = (str) => { + if (typeof str !== 'string') { + throw new Error('Argument should be string') + } + + return str[0].toLocaleUpperCase() + str.slice(1) +} + +export default capitalize diff --git a/String/test/Capitalize.test.js b/String/test/Capitalize.test.js new file mode 100644 index 0000000000..67aa0f76ae --- /dev/null +++ b/String/test/Capitalize.test.js @@ -0,0 +1,9 @@ +import capitalize from '../Capitalize' + +describe('Testing the Capitalize function', () => { + it('returns capitalized strings', () => { + expect(capitalize('hello')).toBe('Hello') + expect(capitalize('HELLO world')).toBe('HELLO world') + expect(capitalize('_ello')).toBe('_ello') + }) +}) diff --git a/package-lock.json b/package-lock.json index 2c86fde142..0cd4eee840 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3094,9 +3094,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001419", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001419.tgz", - "integrity": "sha512-aFO1r+g6R7TW+PNQxKzjITwLOyDhVRLjW0LcwS/HCZGUUKTGNp9+IwLC4xyDSZBygVL/mxaFR3HIV6wEKQuSzw==", + "version": "1.0.30001522", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001522.tgz", + "integrity": "sha512-TKiyTVZxJGhsTszLuzb+6vUZSjVOAhClszBr2Ta2k9IwtNBT/4dzmL6aywt0HCgEZlmwJzXJd8yNiob6HgwTRg==", "funding": [ { "type": "opencollective", @@ -3105,6 +3105,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, @@ -4405,20 +4409,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -10613,9 +10603,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001419", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001419.tgz", - "integrity": "sha512-aFO1r+g6R7TW+PNQxKzjITwLOyDhVRLjW0LcwS/HCZGUUKTGNp9+IwLC4xyDSZBygVL/mxaFR3HIV6wEKQuSzw==" + "version": "1.0.30001522", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001522.tgz", + "integrity": "sha512-TKiyTVZxJGhsTszLuzb+6vUZSjVOAhClszBr2Ta2k9IwtNBT/4dzmL6aywt0HCgEZlmwJzXJd8yNiob6HgwTRg==" }, "chalk": { "version": "2.4.2", @@ -11566,13 +11556,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",