This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

68
node_modules/reading-time/README.md generated vendored Normal file
View File

@@ -0,0 +1,68 @@
# reading-time
[![NPM](http://img.shields.io/npm/v/reading-time.svg)](https://www.npmjs.org/package/reading-time) [![Build Status](http://img.shields.io/travis/ngryman/reading-time.svg)](https://travis-ci.org/ngryman/reading-time)
<br>
[Medium]'s like reading time estimation.
`reading-time` helps you estimate how long an article will take to read.
It works perfectly with plain text, but also with `markdown` or `html`.
Note that it's focused on performance and simplicity, so the number of words it will extract from other formats than plain text can vary a little. But this is an estimation right?
[medium]: https://medium.com
## Installation
```sh
npm install reading-time --production
```
## Usage
### Classic
```javascript
const readingTime = require('reading-time');
const stats = readingTime(text);
// ->
// stats: {
// text: '1 min read',
// minutes: 1,
// time: 60000,
// words: 200
// }
```
### Stream
```javascript
const {readingTimeStream} = require('reading-time');
fs.createReadStream('foo')
.pipe(readingTimeStream)
.on('data', stats => {
// ...
});
```
## API
`readingTime(text, options?)`
- `text`: the text to analyze
- options (optional)
- `options.wordsPerMinute`: (optional) the words per minute an average reader can read (default: 200)
- `options.wordBound`: (optional) a function that returns a boolean value depending on if a character is considered as a word bound (default: spaces, new lines and tabulations)
## Help wanted!
This library has been optimized for alphabetical languages and CJK languages, but may not behave correctly for other languages that don't use spaces for work bounds. If you find the behavior of this library to deviate significantly from your expectation, issues or contributions are welcomed!
## Other projects
- [Fauda](https://github.com/ngryman/fauda): configuration made simple.
- [Badge Size](https://github.com/ngryman/badge-size): Displays the size of a given file in your repository.
- [Commitizen Emoji](https://github.com/ngryman/cz-emoji): Commitizen adapter formatting commit messages using emojis.

38
node_modules/reading-time/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,38 @@
declare module 'reading-time' {
import {Transform, TransformCallback} from 'stream';
export interface Options {
wordBound?: (char: string) => boolean;
wordsPerMinute?: number;
}
export interface ReadTimeResults {
text: string;
time: number;
words: number;
minutes: number;
}
// Retrocompatibility
// TODO: remove in 2.0.0
export type IOptions = Options;
export type IReadTimeResults = ReadTimeResults;
interface ReadingTimeStream extends Transform {
stats: ReadTimeResults;
options: Options;
_transform: (chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback) => void;
_flush: (callback: TransformCallback) => void;
(options?: Options): ReadingTimeStream;
}
const readingTimeStream: ReadingTimeStream;
export {readingTimeStream};
export default function readingTime(text: string, options?: Options): ReadTimeResults;
}
declare module 'reading-time/lib/stream' {
import type {readingTimeStream} from 'reading-time';
export default readingTimeStream;
}

2
node_modules/reading-time/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
module.exports.default = module.exports = require('./lib/reading-time')
module.exports.readingTimeStream = require('./lib/stream')

142
node_modules/reading-time/lib/reading-time.js generated vendored Normal file
View File

@@ -0,0 +1,142 @@
/*!
* reading-time
* Copyright (c) Nicolas Gryman <ngryman@gmail.com>
* MIT Licensed
*/
'use strict'
/**
* @typedef {import('reading-time').Options['wordBound']} WordBoundFunction
*/
/**
* @param {number} number
* @param {number[][]} arrayOfRanges
*/
function codeIsInRanges(number, arrayOfRanges) {
return arrayOfRanges.some(([lowerBound, upperBound]) =>
(lowerBound <= number) && (number <= upperBound)
)
}
/**
* @type {WordBoundFunction}
*/
function isCJK(c) {
if ('string' !== typeof c) {
return false
}
const charCode = c.charCodeAt(0)
// Help wanted!
// This should be good for most cases, but if you find it unsatisfactory
// (e.g. some other language where each character should be standalone words),
// contributions welcome!
return codeIsInRanges(
charCode,
[
// Hiragana (Katakana not included on purpose,
// context: https://github.com/ngryman/reading-time/pull/35#issuecomment-853364526)
// If you think Katakana should be included and have solid reasons, improvement is welcomed
[0x3040, 0x309f],
// CJK Unified ideographs
[0x4e00, 0x9fff],
// Hangul
[0xac00, 0xd7a3],
// CJK extensions
[0x20000, 0x2ebe0]
]
)
}
/**
* @type {WordBoundFunction}
*/
function isAnsiWordBound(c) {
return ' \n\r\t'.includes(c)
}
/**
* @type {WordBoundFunction}
*/
function isPunctuation(c) {
if ('string' !== typeof c) {
return false
}
const charCode = c.charCodeAt(0)
return codeIsInRanges(
charCode,
[
[0x21, 0x2f],
[0x3a, 0x40],
[0x5b, 0x60],
[0x7b, 0x7e],
// CJK Symbols and Punctuation
[0x3000, 0x303f],
// Full-width ASCII punctuation variants
[0xff00, 0xffef]
]
)
}
/**
* @type {import('reading-time').default}
*/
function readingTime(text, options = {}) {
let words = 0, start = 0, end = text.length - 1
// use provided value if available
const wordsPerMinute = options.wordsPerMinute || 200
// use provided function if available
const isWordBound = options.wordBound || isAnsiWordBound
// fetch bounds
while (isWordBound(text[start])) start++
while (isWordBound(text[end])) end--
// Add a trailing word bound to make handling edges more convenient
const normalizedText = `${text}\n`
// calculate the number of words
for (let i = start; i <= end; i++) {
// A CJK character is a always word;
// A non-word bound followed by a word bound / CJK is the end of a word.
if (
isCJK(normalizedText[i]) ||
(!isWordBound(normalizedText[i]) &&
(isWordBound(normalizedText[i + 1]) || isCJK(normalizedText[i + 1]))
)
) {
words++
}
// In case of CJK followed by punctuations, those characters have to be eaten as well
if (isCJK(normalizedText[i])) {
while (
i <= end &&
(isPunctuation(normalizedText[i + 1]) || isWordBound(normalizedText[i + 1]))
) {
i++
}
}
}
// reading time stats
const minutes = words / wordsPerMinute
// Math.round used to resolve floating point funkyness
// http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
const time = Math.round(minutes * 60 * 1000)
const displayed = Math.ceil(minutes.toFixed(2))
return {
text: displayed + ' min read',
minutes: minutes,
time: time,
words: words
}
}
/**
* Export
*/
module.exports = readingTime

72
node_modules/reading-time/lib/stream.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
/*!
* reading-time
* Copyright (c) Nicolas Gryman <ngryman@gmail.com>
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
*/
const readingTime = require('./reading-time')
const Transform = require('stream').Transform
const util = require('util')
/**
* @typedef {import('reading-time').Options} Options
* @typedef {import('reading-time').Options['wordBound']} WordBoundFunction
* @typedef {import('reading-time').readingTimeStream} ReadingTimeStream
* @typedef {import('stream').TransformCallback} TransformCallback
*/
/**
* @param {Options} options
* @returns {ReadingTimeStream}
*/
function ReadingTimeStream(options) {
// allow use without new
if (!(this instanceof ReadingTimeStream)) {
return new ReadingTimeStream(options)
}
Transform.call(this, { objectMode: true })
this.options = options || {}
this.stats = {
minutes: 0,
time: 0,
words: 0
}
}
util.inherits(ReadingTimeStream, Transform)
/**
* @param {Buffer} chunk
* @param {BufferEncoding} encoding
* @param {TransformCallback} callback
*/
ReadingTimeStream.prototype._transform = function(chunk, encoding, callback) {
const stats = readingTime(chunk.toString(encoding), this.options)
this.stats.minutes += stats.minutes
this.stats.time += stats.time
this.stats.words += stats.words
callback()
}
/**
* @param {TransformCallback} callback
*/
ReadingTimeStream.prototype._flush = function(callback) {
this.stats.text = Math.ceil(this.stats.minutes.toFixed(2)) + ' min read'
this.push(this.stats)
callback()
}
/**
* Export
*/
module.exports = ReadingTimeStream

21
node_modules/reading-time/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Nicolas Gryman <ngryman@gmail.com> (ngryman.sh)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

33
node_modules/reading-time/package.json generated vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"name": "reading-time",
"version": "1.5.0",
"description": "Medium's like reading time estimation.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"lint": "eslint lib test",
"spec": "mocha",
"test": "npm run lint && npm run spec",
"watch": "onchange {lib,test}/*.js -- npm test"
},
"repository": "ngryman/reading-time",
"keywords": [
"read",
"time",
"read time",
"reading time",
"medium",
"words per minute"
],
"author": "Nicolas Gryman <ngryman@gmail.com> (http://ngryman.sh)",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"chai": "^4.1.0",
"curry": "^1.2.0",
"eslint": "^3.8.1",
"eslint-config-ngryman": "^1.7.0",
"mocha": "^9.0.3",
"onchange": "^7.1.0"
}
}