Skip to content

Commit

Permalink
chore(deps): update deps
Browse files Browse the repository at this point in the history
BREAKING CHANGE: dropped node<4 support
  • Loading branch information
spudly committed Aug 5, 2016
1 parent a124768 commit 8a41fa2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 52 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
node_js:
- '0.10'
- '0.12'
- '4'
- '5'
- '6'
before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
after_success:
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
Expand Down
8 changes: 6 additions & 2 deletions dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module.exports = {
yes: ['yarr', 'aye'],
are: 'be',
change: 'alter',
folks: 'mateys',
should: 'shall'
folks: 'me hearties',
should: 'shall',
my: 'me',
gentleman: 'pirate',
'gentleman\'s': 'pirate\'s',
wahoo: 'yo ho',
};
36 changes: 16 additions & 20 deletions index.js
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;
14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"test": "npm run lint && mocha --ui exports ./test.js",
"build": "browserify -s talkLikeAPirate ./index.js > ./talk-like-a-pirate.js",
"lint": "eslint index.js dictionary.js test.js",
"lint": "lint index.js dictionary.js test.js",
"prepublish": "npm run build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand All @@ -23,20 +23,12 @@
},
"homepage": "https://github.com/spudly/talk-like-a-pirate",
"devDependencies": {
"@spudly/eslint-config": "^0.1.1",
"@spudly/eslint-config": "^2.1.1",
"browserify": "^13.0.1",
"chai": "^3.5.0",
"mocha": "^3.0.0",
"semantic-release": "^4.3.5",
"sinon": "^1.11.1",
"babel-eslint": "^6.1.2",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-ava": "^2.5.0",
"eslint-plugin-import": "^1.11.1",
"eslint-plugin-jsx-a11y": "^1.5.5",
"eslint-plugin-lodash-fp": "^1.3.0",
"eslint-plugin-react": "^5.2.2"
"sinon": "^1.11.1"
},
"files": [
"index.js",
Expand Down
19 changes: 9 additions & 10 deletions test.js
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);
}

},
};

0 comments on commit 8a41fa2

Please sign in to comment.