Skip to content

Commit

Permalink
Moving to typescript (#1)
Browse files Browse the repository at this point in the history
Moving to typescript
  • Loading branch information
abranhe authored Apr 25, 2019
2 parents 212ebe2 + 5e38e8d commit 453df3f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
26 changes: 26 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
Get to know how long it will take to read a paragraph, text or easy acording
to a [Medium's article](https://help.medium.com/hc/en-us/articles/214991667-Read-time).
Read time is based on the average reading speed of an adult (roughly 265 WPM).
@param input - The input to analize how long it will take to read.
@param textOrWpm - Alternative text you want to introduce, otherwise the reading speed (wpm).
@param wpm - Reading speed, word per minutes (wpm).
Default: `265`.
@example
```
import m2r from 'minutes-to-read';
m2r('Lorem ipsum');
// => less than a min to read
```
*/
declare function m2r(
input: string,
textOrWpm?: number | string,
wpm?: number,
): string;

export = m2r;
7 changes: 7 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {expectType} from 'tsd';
import m2r = require('.');

expectType<string>(m2r('Lorem ipsum'));
expectType<string>(m2r('Lorem ipsum', 1));
expectType<string>(m2r('Lorem ipsum', 'minutes to read'));
expectType<string>(m2r('Lorem ipsum', 'minutes to read', 1));
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "minutes-to-read",
"version": "1.0.1",
"version": "1.0.2",
"description": "Minutes to read",
"main": "index.js",
"scripts": {
"test": "ava & xo"
"test": "ava & xo && tsd"
},
"repository": "abranhe/minutes-to-read",
"author": {
"name": "Abraham Hernandez",
"email": "abraham@abranhe.com",
"url": "https://abranhe.com"
},
"files": [
"index.js"
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"keywords": [
"medium",
"read",
"words",
Expand All @@ -31,7 +32,8 @@
"homepage": "https://p.abranhe.com/minutes-to-read",
"devDependencies": {
"ava": "^1.4.1",
"xo": "^0.24.0"
"xo": "^0.24.0",
"tsd": "^0.7.2"
},
"xo": {
"ignores": [
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const longText = 'Lorem ipsum dolor sit am...' // 500 words
m2r(longText, 'minutes to finish');
// => 2 minutes to finish

m2r(longText, 'minutes to read if you reading rate is 2 wpm', 2);
// => 250 minutes to read if you reading rate is 2 wpm
m2r(longText, 'minutes to read if your reading rate is 2 wpm', 2);
// => 250 minutes to read if your reading rate is 2 wpm
```

## API
Expand Down

0 comments on commit 453df3f

Please sign in to comment.