This repository has been archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
|
||
node_modules | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# utils | ||
# Utils | ||
|
||
Some JavaScript util functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Return the word with the first letter capitalized. | ||
* @param word | ||
* @returns {string} | ||
*/ | ||
function capitalizeWord (word) { | ||
return word.charAt(0).toUpperCase() + word.toLowerCase().slice(1) | ||
} | ||
|
||
/** | ||
* Return the words with the first letter capitalized. | ||
* @param words | ||
* @returns {string} | ||
*/ | ||
function capitalizeWords (words) { | ||
return words.split(' ').map(capitalizeWord).join(' ') | ||
} | ||
|
||
/** | ||
* Return an array of word with first letter capitalized. | ||
* @param wordList | ||
* @returns {string[]} | ||
*/ | ||
function capitalizeWordList (wordList) { | ||
return wordList.map(capitalizeWords) | ||
} | ||
|
||
// Exports | ||
module.exports = { | ||
capitalizeWord, | ||
capitalizeWords, | ||
capitalizeWordList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "utils", | ||
"version": "0.1.0", | ||
"author": "Omar Desogus", | ||
"description": "Some JavaScript util functions.", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha test.js" | ||
}, | ||
"homepage": "https://github.com/cedoor/utils#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/cedoor/utils.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/cedoor/utils/issues" | ||
}, | ||
"devDependencies": { | ||
"mocha": "5.2.0", | ||
"standard": "12.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const assert = require('assert') | ||
const utils = require('./index.js') | ||
|
||
describe('Capitalization', function () { | ||
describe('#capitalizeWord()', function () { | ||
it('should return the word with the first letter capitalized', function () { | ||
const result = utils.capitalizeWord('heLlO') | ||
assert.equal(result, 'Hello') | ||
}) | ||
}) | ||
|
||
describe('#capitalizeWords()', function () { | ||
it('should return the words with the first letter capitalized', function () { | ||
const result = utils.capitalizeWords('heLlO worLd') | ||
assert.equal(result, 'Hello World') | ||
}) | ||
}) | ||
|
||
describe('#capitalizeWordList()', function () { | ||
it('should return an array of word with first letter capitalized', function () { | ||
const result = utils.capitalizeWordList(['heLlO', 'heLlO worLd']).join(', ') | ||
assert.equal(result, 'Hello, Hello World') | ||
}) | ||
}) | ||
}) |