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

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