From cad01b77adf63d7ff860f4518131def78fc80414 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 21 Aug 2021 11:27:01 +0200 Subject: [PATCH] update dependencies and switch from eslint to prettier --- .eslintrc | 14 ------------ .travis.yml | 15 ++++++++---- README.md | 2 -- index.js | 54 ++++++++++++++++++++++---------------------- package.json | 10 ++++---- prettier.config.js | 9 ++++++++ test/jeffsum.spec.js | 50 ++++++++++++++++++++-------------------- 7 files changed, 74 insertions(+), 80 deletions(-) delete mode 100644 .eslintrc create mode 100644 prettier.config.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 953380a..0000000 --- a/.eslintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "airbnb-base", - "rules": { - "no-use-before-define": [ - "error", { - "functions": false - } - ], - "linebreak-style": 0 - }, - "env": { - "browser": true - } -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 736d6b3..2dc0f8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file + - npm test diff --git a/README.md b/README.md index 0489b8e..f614f75 100644 --- a/README.md +++ b/README.md @@ -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) -Buy Me A Coffee - ## Install ``` npm install jeffsum -D diff --git a/index.js b/index.js index f9f2a73..7e6d0d2 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/package.json b/package.json index 433a7c9..22557c0 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..cbedc14 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,9 @@ +module.exports = { + trailingComma: 'es5', + tabWidth: 2, + semi: false, + singleQuote: true, + useTabs: false, + quoteProps: 'consistent', + printWidth: 120, +} diff --git a/test/jeffsum.spec.js b/test/jeffsum.spec.js index 3e6a3d9..c56bd45 100644 --- a/test/jeffsum.spec.js +++ b/test/jeffsum.spec.js @@ -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) + }) + }) +})