Created
March 21, 2020 15:41
-
-
Save AutoSponge/f67292428488a6252c70286c8a2efec4 to your computer and use it in GitHub Desktop.
betterer-test
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
const got = require('got'); | |
const cheerio = require('cheerio'); | |
const natural = require('natural'); | |
const sentenceTokenizer = new natural.SentenceTokenizer(); | |
const wordTokenizer = new natural.WordTokenizer(); | |
const automatedReadability = require('automated-readability'); | |
const page = 'https://www.24a11y.com/2019/automating-inclusive-documentation/'; | |
const { smaller } = require('@betterer/constraints'); | |
module.exports = { | |
readability: { | |
test: async () => { | |
const response = await got(page); | |
const $ = cheerio.load(response.body); | |
const paragraphs = $('p') | |
.toArray() | |
.flatMap((p) => $(p).text().trim() || []); | |
const content = paragraphs.join('\n'); | |
const sentences = sentenceTokenizer.tokenize(content); | |
const words = wordTokenizer.tokenize(content); | |
const counts = { | |
sentence: sentences.length, | |
word: words.length, | |
character: content.match(/[a-z]/gim).length | |
}; | |
const value = automatedReadability(counts); | |
return value; | |
}, | |
constraint: smaller, | |
goal: 7 | |
}, | |
'reading-time': { | |
test: async () => { | |
const response = await got(page); | |
const $ = cheerio.load(response.body); | |
const paragraphs = $('p') | |
.toArray() | |
.flatMap((p) => $(p).text().trim() || []); | |
const content = paragraphs.join('\n'); | |
const words = wordTokenizer.tokenize(content); | |
return words.length / 240; | |
}, | |
constraint: smaller, | |
goal: 5 | |
} | |
}; |
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
{ | |
"name": "betterer-test", | |
"version": "1.0.0", | |
"description": "example use of betterer", | |
"scripts": { | |
"test": "npm run betterer -s", | |
"betterer": "betterer" | |
}, | |
"author": "Paul <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"@betterer/cli": "^0.5.2", | |
"automated-readability": "^1.0.5", | |
"cheerio": "^1.0.0-rc.3", | |
"got": "^10.6.0", | |
"jsdom": "^16.2.0", | |
"natural": "^0.6.3" | |
}, | |
"devDependencies": { | |
"typescript": "^3.8.3", | |
"@betterer/cli": "^0.5.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment