Skip to content

Commit

Permalink
chore: add linting
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptammergard committed Dec 17, 2021
1 parent 3977cf2 commit 56e2a73
Show file tree
Hide file tree
Showing 10 changed files with 4,546 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@tammergard/eslint-config-base"],
}
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16

- name: Review
run: yarn review

release:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16

- name: Review
run: yarn review

- name: Build
run: yarn build

- name: Run semantic-release
run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@tammergard/prettier-config"),
}
3 changes: 3 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: "@tammergard/semantic-release-config-npm",
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import {
countWords,
countSequences,
getReadingTime,
} from "text-analyzer";
} from "text-analyzer"

const text =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

const characters = countCharacters(text);
const characters = countCharacters(text)
// characters = 445

const words = countWords(text);
const words = countWords(text)
// words = 69

const sequences = countSequences(text, "dolor");
const sequences = countSequences(text, "dolor")
// sequences = 4

const readingTime = getReadingTime(text);
const readingTime = getReadingTime(text)
/*
readingTime = {
milliseconds: 20700
Expand Down
23 changes: 11 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
export function countCharacters(text: string) {
const characters = text.length;
return characters;
const characters = text.length
return characters
}

export function countWords(text: string) {
const words = text.split(/ |\t|\n|\r/).filter((word) => word !== "").length;
return words;
const words = text.split(/ |\t|\n|\r/).filter((word) => word !== "").length
return words
}

export function countSequenceOccurances(text: string, sequence: string) {
const occurances =
text.toLowerCase().split(sequence.toLowerCase()).length - 1;
return occurances;
const occurances = text.toLowerCase().split(sequence.toLowerCase()).length - 1
return occurances
}

const WORDS_PER_MINUTE = 200;
const WORDS_PER_MINUTE = 200

export function getReadingTime(text: string) {
const words = countWords(text);
const minutes = words / WORDS_PER_MINUTE;
const milliseconds = minutes * 60 * 1000;
const words = countWords(text)
const minutes = words / WORDS_PER_MINUTE
const milliseconds = minutes * 60 * 1000
return {
words,
minutes,
milliseconds,
};
}
}
111 changes: 0 additions & 111 deletions package-lock.json

This file was deleted.

32 changes: 21 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
"name": "text-analyzer",
"version": "1.5.0",
"description": "Utility functions providing possibilities to analyze text.",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"prettier": "prettier --write .",
"review": "yarn install --frozen-lockfile && yarn lint && yarn prettier"
},
"devDependencies": {
"@tammergard/eslint-config-base": "2.2.0",
"@tammergard/prettier-config": "1.4.0",
"@tammergard/semantic-release-config-npm": "1.0.0",
"eslint": "8.4.1",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-prettier": "4.0.0",
"prettier": "2.5.1",
"semantic-release": "18.0.1",
"typescript": "4.5.4"
},
"author": "Filip Tammergård <[email protected]> (https://tammergard.se)",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist/index.js",
"dist/index.d.ts"
],
"author": "Filip Tammergård <[email protected]> (https://tammergard.se)",
"license": "MIT",
"scripts": {
"prebuild": "rimraf dist/",
"build": "tsc",
"npm-publish": "npm run build && npm publish",
"postnpm-publish": "rimraf dist/"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^4.2.4"
},
"repository": {
"type": "git",
"url": "https://github.com/filiptammergard/text-analyzer.git"
Expand Down
Loading

0 comments on commit 56e2a73

Please sign in to comment.