-
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.
BREAKING CHANGE: dropped node<4 support
- Loading branch information
Showing
5 changed files
with
34 additions
and
52 deletions.
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
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
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,28 +1,24 @@ | ||
dictionary = require('./dictionary'); | ||
const dictionary = require('./dictionary'); | ||
|
||
function isUpperCase(char) { | ||
return char.toUpperCase() === char; | ||
} | ||
const isUpperCase = char => char.toUpperCase() === char; | ||
|
||
function talkLikeAPirate(str) { | ||
return str.replace(/[\w']+/ig, function(match) { | ||
var replacement = dictionary[match.toLowerCase()]; | ||
const talkLikeAPirate = str => str.replace(/[\w']+/ig, match => { | ||
let replacement = dictionary[match.toLowerCase()]; | ||
|
||
if (!replacement) { | ||
return match; | ||
} | ||
if (!replacement) { | ||
return match; | ||
} | ||
|
||
if (Array.isArray(replacement)) { | ||
// get array element at random | ||
replacement = replacement[Math.floor(Math.random() * replacement.length)]; | ||
} | ||
if (Array.isArray(replacement)) { | ||
// get array element at random | ||
replacement = replacement[Math.floor(Math.random() * replacement.length)]; | ||
} | ||
|
||
if (isUpperCase(match[0])) { | ||
replacement = replacement[0].toUpperCase() + replacement.slice(1); | ||
} | ||
if (isUpperCase(match[0])) { | ||
replacement = replacement[0].toUpperCase() + replacement.slice(1); | ||
} | ||
|
||
return replacement; | ||
}); | ||
} | ||
return replacement; | ||
}); | ||
|
||
module.exports = talkLikeAPirate; |
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
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,17 +1,16 @@ | ||
talkLikeAPirate = require('./index'); | ||
assert = require('chai').assert; | ||
sinon = require('sinon'); | ||
const talkLikeAPirate = require('./index'); | ||
const assert = require('chai').assert; | ||
const sinon = require('sinon'); | ||
|
||
sinon.stub(Math, 'random').returns(0); | ||
assert.strictEqual(Math.random(), 0, 'stub worked'); | ||
|
||
module.exports = { | ||
|
||
'talk-like-a-pirate': function() { | ||
var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; | ||
var actual = talkLikeAPirate(text); | ||
var expected = "Lorem Ipsum be simply dummy text of ye printing and typesetting industry. Lorem Ipsum has been ye industry's standard dummy text ever since ye 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also ye leap into electronic typesetting, remaining essentially unchanged. It was popularised in ye 1960s with ye release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; | ||
'talk-like-a-pirate': () => { | ||
const text = 'Drink up folks, wahoo! A gentleman\'s life for me!'; | ||
const actual = talkLikeAPirate(text); | ||
console.log(actual); // eslint-disable-line | ||
const expected = 'Drink up me hearties, yo ho! A pirate\'s life for me!'; | ||
assert(actual === expected); | ||
} | ||
|
||
}, | ||
}; |