Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
[init] create base structure
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Nov 27, 2018
1 parent 8a79420 commit e6c7333
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea

node_modules
package-lock.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# utils
# Utils

Some JavaScript util functions.
33 changes: 33 additions & 0 deletions index.js
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
}
23 changes: 23 additions & 0 deletions package.json
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"
}
}
25 changes: 25 additions & 0 deletions test.js
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')
})
})
})

0 comments on commit e6c7333

Please sign in to comment.