Skip to content

Instantly share code, notes, and snippets.

@nickheal
Created April 11, 2020 13:42
Show Gist options
  • Save nickheal/7f8012266aa12bc4c4c280ff5e23ce91 to your computer and use it in GitHub Desktop.
Save nickheal/7f8012266aa12bc4c4c280ff5e23ce91 to your computer and use it in GitHub Desktop.
The joy of pipelines
import { JSDOM } from 'jsdom';
import getAverageWordLength from './common/getAverageWordLength';
import getElements from './common/getElements';
import getSentences from './common/getSentences';
import getWords from './common/getWords';
import stripSpecialCharacters from './common/stripSpecialCharacters';
/**
* Gets the average word length from a page
* @param {string} html - the html to process
*/
export default (html) => {
const { window: { document: { body } } } = new JSDOM(html);
return body
|> getElements
|> getSentences
|> getWords
|> stripSpecialCharacters
|> getAverageWordLength;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment