-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial work * Still return words * Update README * Change API * Update README * Address suggestions Signed-off-by: Josh-Cena <[email protected]> * Update README.md
- Loading branch information
Showing
8 changed files
with
137 additions
and
185 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"words per minute" | ||
], | ||
"author": "Nicolas Gryman <[email protected]> (http://ngryman.sh)", | ||
"contributors": ["Joshua Chen <[email protected]> (https://joshcena.com)"], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/chai": "^4.2.21", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import readingTime from './reading-time' | ||
import readingTime, { countWords, readingTimeWithCount } from './reading-time' | ||
import ReadingTimeStream from './stream' | ||
|
||
// This part is to make TS happy | ||
export { ReadingTimeStream } | ||
export { ReadingTimeStream, countWords, readingTimeWithCount } | ||
export default readingTime | ||
|
||
// Wacky way to support const readingTime = require('reading-time') :( | ||
// Basically we can't use ES import/export anymore because re-assigning module.exports | ||
// decouples it from the exports object, which TS export compiles to | ||
module.exports = readingTime | ||
module.exports.default = readingTime | ||
module.exports.countWords = countWords | ||
module.exports.readingTimeWithCount = readingTimeWithCount | ||
module.exports.ReadingTimeStream = ReadingTimeStream | ||
module.exports.__esModule = true |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
declare module 'reading-time' { | ||
import { Transform, TransformCallback } from 'stream' | ||
|
||
export interface Options { | ||
export type Options = { | ||
wordBound?: (char: string) => boolean; | ||
wordsPerMinute?: number; | ||
} | ||
|
||
export interface ReadTimeResults { | ||
text: string; | ||
export type ReadingTimeStats = { | ||
time: number; | ||
words: number; | ||
minutes: number; | ||
} | ||
|
||
export type WordCountStats = { | ||
total: number; | ||
} | ||
|
||
export class ReadingTimeStream extends Transform { | ||
stats: ReadTimeResults; | ||
stats: WordCountStats; | ||
options: Options; | ||
constructor(options?: Options); | ||
_transform: (chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback) => void; | ||
_flush: (callback: TransformCallback) => void; | ||
} | ||
|
||
export default function readingTime(text: string, options?: Options): ReadTimeResults | ||
export type ReadingTimeResult = ReadingTimeStats & { | ||
words: WordCountStats; | ||
} | ||
|
||
export function countWords(text: string, options?: Options): WordCountStats | ||
export function readingTimeWithCount(words: WordCountStats, options?: Options): ReadingTimeStats | ||
export default function readingTime(text: string, options?: Options): ReadingTimeResult | ||
} |
Oops, something went wrong.