Skip to content

Commit

Permalink
update dependencies and switch from eslint to prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
christophervoigt committed Aug 21, 2021
1 parent f3fede3 commit cad01b7
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 80 deletions.
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ sudo: false

language: node_js
node_js:
- "11"
- "10"
- "9"
- "8"
- '16'
- '15'
- '14'
- '13'
- '12'
- '11'
- '10'
- '9'
- '8'

script:
- npm test
- npm test
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Jeff Goldblum text placeholder generator of pure amazingness. (original by @sean
[![NPM Version](http://img.shields.io/npm/v/jeffsum.svg?style=flat)](https://www.npmjs.com/package/jeffsum)
[![NPM Downloads](https://img.shields.io/npm/dm/jeffsum.svg?style=flat)](https://npmcharts.com/compare/jeffsum?minimal=true)

<a href="https://www.buymeacoffee.com/chlorophyllkid" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-green.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

## Install
```
npm install jeffsum -D
Expand Down
54 changes: 27 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,64 +34,64 @@ const quotes = [
"I, uh, don't think I'm, y'know, so different than your average, y'know, average.",
"It's a delight to trust somebody so completely.",
"It's nice to play a character that has a soulful, dependent, close relationship. It must mean my character is interesting in some way.",
];
]

function jeffsum(amount, type) {
if (isNaN(amount)) {
throw new Error('amount of text must be a number');
throw new Error('amount of text must be a number')
}

const number = Math.floor(amount);
const number = Math.floor(amount)

if (number <= 0) {
throw new Error('amount of text must be greater than 0');
throw new Error('amount of text must be greater than 0')
}

let result = '';
let result = ''

// create a full text from quotes
let jeffsumText = '';
let jeffsumText = ''
quotes.forEach(() => {
const randomSentence = quotes[Math.floor(Math.random() * quotes.length)];
jeffsumText += `${randomSentence} `;
});
const randomSentence = quotes[Math.floor(Math.random() * quotes.length)]
jeffsumText += `${randomSentence} `
})

// create a list of words
let jeffsumWordArray = [];
let jeffsumWordArray = []

// create a list of sentences
let jeffsumSentenceArray = [];
let jeffsumSentenceArray = []

switch (type) {
case 'characters':
result = jeffsumText.substr(0, number);
break;
result = jeffsumText.substr(0, number)
break

case 'words':
jeffsumText = jeffsumText.split('.').join('');
jeffsumText = jeffsumText.split(',').join('');
jeffsumText = jeffsumText.split('?').join('');
jeffsumText = jeffsumText.split('!').join('');
jeffsumWordArray = jeffsumText.split(' ');
jeffsumText = jeffsumText.split('.').join('')
jeffsumText = jeffsumText.split(',').join('')
jeffsumText = jeffsumText.split('?').join('')
jeffsumText = jeffsumText.split('!').join('')
jeffsumWordArray = jeffsumText.split(' ')

for (let i = 0; i < number; i += 1) {
result += `${jeffsumWordArray[Math.floor(Math.random() * jeffsumWordArray.length)]} `;
result += `${jeffsumWordArray[Math.floor(Math.random() * jeffsumWordArray.length)]} `
}
result = result.slice(0, result.length - 1);
break;
result = result.slice(0, result.length - 1)
break

default:
case 'sentences':
jeffsumSentenceArray = jeffsumText.match(/[^.!?]+[.!?] /g);
jeffsumSentenceArray = jeffsumText.match(/[^.!?]+[.!?] /g)

for (let j = 0; j < number; j += 1) {
result += jeffsumSentenceArray[Math.floor(Math.random() * jeffsumSentenceArray.length)];
result += jeffsumSentenceArray[Math.floor(Math.random() * jeffsumSentenceArray.length)]
}
result = result.slice(0, result.length - 1);
break;
result = result.slice(0, result.length - 1)
break
}

return result;
return result
}

module.exports = jeffsum;
module.exports = jeffsum
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"homepage": "http://jeffsum.com/",
"main": "index.js",
"scripts": {
"lint": "eslint --quiet index.js test/**/*.js",
"lint": "prettier --config prettier.config.js --check {./test/**/*.js,*{.js,.json}} --write",
"test": "mocha"
},
"repository": {
Expand All @@ -25,10 +25,8 @@
"generator"
],
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.2",
"mocha": "^6.1.4"
"chai": "^4.3.4",
"mocha": "^9.1.0",
"prettier": "^2.3.2"
}
}
9 changes: 9 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: false,
singleQuote: true,
useTabs: false,
quoteProps: 'consistent',
printWidth: 120,
}
50 changes: 24 additions & 26 deletions test/jeffsum.spec.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
/* global describe, it */

const { assert } = require('chai');
const { assert } = require('chai')

const jeffsum = require('../index.js');
const jeffsum = require('../index.js')

describe('jeffsum...', () => {
describe('works, when...', () => {
it('it returns 5 characters on jeffsum(5, "characters").', () => {
const text = jeffsum(5, 'characters');
assert.lengthOf(text, 5);
});
const text = jeffsum(5, 'characters')
assert.lengthOf(text, 5)
})

it('it returns 5 space separated words on jeffsum(5, "words").', () => {
const text = jeffsum(5, 'words');
const numOfSpaces = (text.match(/ /g)).length;
assert.equal(numOfSpaces, 4);
});
const text = jeffsum(5, 'words')
const numOfSpaces = text.match(/ /g).length
assert.equal(numOfSpaces, 4)
})

it('it returns 5 sentences on jeffsum(5, "sentences").', () => {
const text = jeffsum(5, 'sentences');
const numOfDots = (text.match(/[^.!?]+[.!?]/g)).length;
assert.equal(numOfDots, 5);
});
});
const text = jeffsum(5, 'sentences')
const numOfDots = text.match(/[^.!?]+[.!?]/g).length
assert.equal(numOfDots, 5)
})
})

describe('fails, when...', () => {
it('first parameter is not a number.', () => {
assert.throws(
() => { jeffsum('five', 'sentences'); },
Error,
);
});
assert.throws(() => {
jeffsum('five', 'sentences')
}, Error)
})

it('first parameter smaller than 0', () => {
assert.throws(
() => { jeffsum(-1, 'sentences'); },
Error,
);
});
});
});
assert.throws(() => {
jeffsum(-1, 'sentences')
}, Error)
})
})
})

0 comments on commit cad01b7

Please sign in to comment.