@utilix-tech/sdk 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/{chunk-FXBB7O5A.js → chunk-5CKOJXFU.js} +59 -2
- package/dist/{chunk-YBBYFAOV.js → chunk-F57WMKZO.js} +69 -1
- package/dist/index.cjs +126 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{media-CHaBS1dI.d.cts → media-D66WnthC.d.cts} +27 -2
- package/dist/{media-CHaBS1dI.d.ts → media-D66WnthC.d.ts} +27 -2
- package/dist/{text-CI7JAl7F.d.cts → text-Bbx-tZ43.d.cts} +23 -2
- package/dist/{text-CI7JAl7F.d.ts → text-Bbx-tZ43.d.ts} +23 -2
- package/dist/tools/media.cjs +57 -0
- package/dist/tools/media.d.cts +1 -1
- package/dist/tools/media.d.ts +1 -1
- package/dist/tools/media.js +1 -1
- package/dist/tools/text.cjs +68 -0
- package/dist/tools/text.d.cts +1 -1
- package/dist/tools/text.d.ts +1 -1
- package/dist/tools/text.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @utilix-tech/sdk
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**526 developer utility functions for Node.js: runs locally, no API key required.**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@utilix-tech/sdk)
|
|
6
6
|
[](https://www.npmjs.com/package/@utilix-tech/sdk)
|
|
@@ -127,7 +127,7 @@ generateHtpasswdFile([{ username: "alice", password: "secret" }]);
|
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
129
|
import { convertCase, slugify, countWords, generateWords, generateParagraphs,
|
|
130
|
-
escapeString, htmlToMarkdown, applyOps, detectPassiveVoice } from "@utilix-tech/sdk/text";
|
|
130
|
+
escapeString, htmlToMarkdown, applyOps, detectPassiveVoice, scoreReadability } from "@utilix-tech/sdk/text";
|
|
131
131
|
|
|
132
132
|
convertCase("hello world", "camelCase"); // "helloWorld"
|
|
133
133
|
convertCase("hello world", "PascalCase"); // "HelloWorld"
|
|
@@ -148,6 +148,10 @@ htmlToMarkdown("<h1>Hello</h1><p>World</p>");
|
|
|
148
148
|
|
|
149
149
|
// Flag passive-voice sentences, e.g. "was written", "were approved by the team"
|
|
150
150
|
detectPassiveVoice("The report was reviewed by the committee. They approved it.");
|
|
151
|
+
|
|
152
|
+
// Flesch Reading Ease, Flesch-Kincaid Grade Level, and Gunning Fog Index
|
|
153
|
+
scoreReadability("The cat sat on the mat. It was a sunny day.");
|
|
154
|
+
// { fleschReadingEase: 109, fleschKincaidGrade: -0.6, gunningFog: 2.2, readingLevel: "Very easy (5th grade)", ... }
|
|
151
155
|
```
|
|
152
156
|
|
|
153
157
|
---
|
|
@@ -416,10 +420,10 @@ analyzeString("café"); // { length: 4, codePoints: [...], ... }
|
|
|
416
420
|
|
|
417
421
|
---
|
|
418
422
|
|
|
419
|
-
### `/media`: Image Header Parsing, EXIF &
|
|
423
|
+
### `/media`: Image Header Parsing, EXIF, PDF & WAV Metadata
|
|
420
424
|
|
|
421
425
|
```ts
|
|
422
|
-
import { readImageInfo, readExifData, readPdfMetadata } from "@utilix-tech/sdk/media";
|
|
426
|
+
import { readImageInfo, readExifData, readPdfMetadata, readWavInfo } from "@utilix-tech/sdk/media";
|
|
423
427
|
|
|
424
428
|
// Reads format, dimensions, bit depth, and alpha channel straight from
|
|
425
429
|
// file bytes: no decoding, no canvas, no image library.
|
|
@@ -438,9 +442,15 @@ readExifData(new Uint8Array(jpegBytes));
|
|
|
438
442
|
const pdfBytes = await fs.promises.readFile("report.pdf");
|
|
439
443
|
readPdfMetadata(new Uint8Array(pdfBytes));
|
|
440
444
|
// { version: "1.7", pageCount: 12, title: "Q3 Report", author: "Jane Doe", ... }
|
|
445
|
+
|
|
446
|
+
// Reads sample rate, channels, bit depth, and duration from a WAV file's
|
|
447
|
+
// RIFF/fmt/data chunk headers: no audio library required.
|
|
448
|
+
const wavBytes = await fs.promises.readFile("recording.wav");
|
|
449
|
+
readWavInfo(new Uint8Array(wavBytes));
|
|
450
|
+
// { audioFormat: 1, audioFormatLabel: "PCM", channels: 2, sampleRate: 44100, bitsPerSample: 16, durationSeconds: 12.4, ... }
|
|
441
451
|
```
|
|
442
452
|
|
|
443
|
-
`readImageInfo` supports PNG, JPEG, GIF, WebP, and BMP. `readExifData` supports JPEG only.
|
|
453
|
+
`readImageInfo` supports PNG, JPEG, GIF, WebP, and BMP. `readExifData` supports JPEG only. `readWavInfo` supports the canonical RIFF/WAVE container only.
|
|
444
454
|
|
|
445
455
|
---
|
|
446
456
|
|
|
@@ -463,7 +473,7 @@ readPdfMetadata(new Uint8Array(pdfBytes));
|
|
|
463
473
|
| `@utilix-tech/sdk/css` | CSS gradient, box-shadow, border-radius, keyframe animation generators |
|
|
464
474
|
| `@utilix-tech/sdk/misc` | SVG optimize/sanitize, file size format, Unicode inspector |
|
|
465
475
|
| `@utilix-tech/sdk/ai_agent` | Token estimate/trim, chunk text, extract URLs/JSON/keywords, sanitize HTML, flatten/merge JSON, dedupe lines, validate schema, PII/secret/injection detect |
|
|
466
|
-
| `@utilix-tech/sdk/media` | Image format & dimension reading from raw bytes (PNG, JPEG, GIF, WebP, BMP); PDF metadata reading |
|
|
476
|
+
| `@utilix-tech/sdk/media` | Image format & dimension reading from raw bytes (PNG, JPEG, GIF, WebP, BMP); PDF metadata reading; WAV audio info |
|
|
467
477
|
|
|
468
478
|
---
|
|
469
479
|
|
|
@@ -5,7 +5,8 @@ var media_exports = {};
|
|
|
5
5
|
__export(media_exports, {
|
|
6
6
|
readExifData: () => readExifData,
|
|
7
7
|
readImageInfo: () => readImageInfo,
|
|
8
|
-
readPdfMetadata: () => readPdfMetadata
|
|
8
|
+
readPdfMetadata: () => readPdfMetadata,
|
|
9
|
+
readWavInfo: () => readWavInfo
|
|
9
10
|
});
|
|
10
11
|
function readU32BE(bytes, offset) {
|
|
11
12
|
return (bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]) >>> 0;
|
|
@@ -463,5 +464,61 @@ function readPdfMetadata(bytes) {
|
|
|
463
464
|
encrypted
|
|
464
465
|
};
|
|
465
466
|
}
|
|
467
|
+
var AUDIO_FORMAT_LABELS = {
|
|
468
|
+
1: "PCM",
|
|
469
|
+
3: "IEEE float",
|
|
470
|
+
6: "A-law",
|
|
471
|
+
7: "mu-law",
|
|
472
|
+
65534: "Extensible"
|
|
473
|
+
};
|
|
474
|
+
function readAscii4(bytes, offset) {
|
|
475
|
+
return String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
|
|
476
|
+
}
|
|
477
|
+
function readWavInfo(bytes) {
|
|
478
|
+
if (bytes.length < 12) return { error: "File is too small to be a valid WAV file" };
|
|
479
|
+
if (readAscii4(bytes, 0) !== "RIFF") return { error: 'Not a RIFF file (missing "RIFF" header)' };
|
|
480
|
+
if (readAscii4(bytes, 8) !== "WAVE") return { error: 'Not a WAVE file (missing "WAVE" format marker)' };
|
|
481
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
482
|
+
const fileSize = view.getUint32(4, true) + 8;
|
|
483
|
+
let offset = 12;
|
|
484
|
+
let fmt = null;
|
|
485
|
+
let dataSize = null;
|
|
486
|
+
while (offset + 8 <= bytes.length) {
|
|
487
|
+
const chunkId = readAscii4(bytes, offset);
|
|
488
|
+
const chunkSize = view.getUint32(offset + 4, true);
|
|
489
|
+
const dataOffset = offset + 8;
|
|
490
|
+
if (chunkId === "fmt ") {
|
|
491
|
+
if (dataOffset + 16 > bytes.length) return { error: 'Truncated "fmt " chunk' };
|
|
492
|
+
fmt = {
|
|
493
|
+
audioFormat: view.getUint16(dataOffset, true),
|
|
494
|
+
channels: view.getUint16(dataOffset + 2, true),
|
|
495
|
+
sampleRate: view.getUint32(dataOffset + 4, true),
|
|
496
|
+
byteRate: view.getUint32(dataOffset + 8, true),
|
|
497
|
+
blockAlign: view.getUint16(dataOffset + 12, true),
|
|
498
|
+
bitsPerSample: view.getUint16(dataOffset + 14, true)
|
|
499
|
+
};
|
|
500
|
+
} else if (chunkId === "data") {
|
|
501
|
+
dataSize = Math.min(chunkSize, bytes.length - dataOffset);
|
|
502
|
+
}
|
|
503
|
+
offset = dataOffset + chunkSize + chunkSize % 2;
|
|
504
|
+
if (fmt && dataSize !== null) break;
|
|
505
|
+
}
|
|
506
|
+
if (!fmt) return { error: 'No "fmt " chunk found in this WAV file' };
|
|
507
|
+
if (dataSize === null) return { error: 'No "data" chunk found in this WAV file' };
|
|
508
|
+
if (fmt.byteRate <= 0) return { error: 'Invalid byte rate in "fmt " chunk' };
|
|
509
|
+
const durationSeconds = Math.round(dataSize / fmt.byteRate * 1e3) / 1e3;
|
|
510
|
+
return {
|
|
511
|
+
audioFormat: fmt.audioFormat,
|
|
512
|
+
audioFormatLabel: AUDIO_FORMAT_LABELS[fmt.audioFormat] ?? `Unknown (0x${fmt.audioFormat.toString(16)})`,
|
|
513
|
+
channels: fmt.channels,
|
|
514
|
+
sampleRate: fmt.sampleRate,
|
|
515
|
+
byteRate: fmt.byteRate,
|
|
516
|
+
blockAlign: fmt.blockAlign,
|
|
517
|
+
bitsPerSample: fmt.bitsPerSample,
|
|
518
|
+
dataSize,
|
|
519
|
+
durationSeconds,
|
|
520
|
+
fileSize
|
|
521
|
+
};
|
|
522
|
+
}
|
|
466
523
|
|
|
467
|
-
export { media_exports, readExifData, readImageInfo, readPdfMetadata };
|
|
524
|
+
export { media_exports, readExifData, readImageInfo, readPdfMetadata, readWavInfo };
|
|
@@ -51,6 +51,7 @@ __export(text_exports, {
|
|
|
51
51
|
readabilityScore: () => readabilityScore,
|
|
52
52
|
renderMarkdown: () => renderMarkdown,
|
|
53
53
|
romanToNumber: () => romanToNumber,
|
|
54
|
+
scoreReadability: () => scoreReadability,
|
|
54
55
|
sentenceCount: () => sentenceCount,
|
|
55
56
|
slugify: () => slugify,
|
|
56
57
|
slugifyAll: () => slugifyAll,
|
|
@@ -2389,5 +2390,72 @@ function detectPassiveVoice(text) {
|
|
|
2389
2390
|
const passivePercent = totalSentences > 0 ? Math.round(passiveSentences / totalSentences * 1e3) / 10 : 0;
|
|
2390
2391
|
return { sentences: analyzed, totalSentences, passiveSentences, passivePercent };
|
|
2391
2392
|
}
|
|
2393
|
+
function countSyllables(word) {
|
|
2394
|
+
const w = word.toLowerCase().replace(/[^a-z]/g, "");
|
|
2395
|
+
if (w.length === 0) return 0;
|
|
2396
|
+
if (w.length <= 3) return 1;
|
|
2397
|
+
let count = 0;
|
|
2398
|
+
let prevWasVowel = false;
|
|
2399
|
+
for (const ch of w) {
|
|
2400
|
+
const isVowel = "aeiouy".includes(ch);
|
|
2401
|
+
if (isVowel && !prevWasVowel) count++;
|
|
2402
|
+
prevWasVowel = isVowel;
|
|
2403
|
+
}
|
|
2404
|
+
if (w.endsWith("e") && !w.endsWith("le") && count > 1) count--;
|
|
2405
|
+
if (w.endsWith("le") && w.length > 2 && !"aeiouy".includes(w[w.length - 3])) count++;
|
|
2406
|
+
return Math.max(count, 1);
|
|
2407
|
+
}
|
|
2408
|
+
function readabilityGradeLabel(fleschReadingEase) {
|
|
2409
|
+
if (fleschReadingEase >= 90) return "Very easy (5th grade)";
|
|
2410
|
+
if (fleschReadingEase >= 80) return "Easy (6th grade)";
|
|
2411
|
+
if (fleschReadingEase >= 70) return "Fairly easy (7th grade)";
|
|
2412
|
+
if (fleschReadingEase >= 60) return "Standard (8th-9th grade)";
|
|
2413
|
+
if (fleschReadingEase >= 50) return "Fairly difficult (10th-12th grade)";
|
|
2414
|
+
if (fleschReadingEase >= 30) return "Difficult (college)";
|
|
2415
|
+
return "Very difficult (college graduate)";
|
|
2416
|
+
}
|
|
2417
|
+
function round1(n) {
|
|
2418
|
+
return Math.round(n * 10) / 10;
|
|
2419
|
+
}
|
|
2420
|
+
function scoreReadability(text) {
|
|
2421
|
+
const sentences = splitIntoSentences(text);
|
|
2422
|
+
const words = text.match(/[a-zA-Z']+/g) ?? [];
|
|
2423
|
+
const sentenceCount2 = Math.max(sentences.length, 1);
|
|
2424
|
+
const wordCount = words.length;
|
|
2425
|
+
const syllableCounts = words.map(countSyllables);
|
|
2426
|
+
const syllableCount2 = syllableCounts.reduce((a, b) => a + b, 0);
|
|
2427
|
+
const complexWordCount = syllableCounts.filter((c) => c >= 3).length;
|
|
2428
|
+
if (wordCount === 0) {
|
|
2429
|
+
return {
|
|
2430
|
+
wordCount: 0,
|
|
2431
|
+
sentenceCount: 0,
|
|
2432
|
+
syllableCount: 0,
|
|
2433
|
+
complexWordCount: 0,
|
|
2434
|
+
avgWordsPerSentence: 0,
|
|
2435
|
+
avgSyllablesPerWord: 0,
|
|
2436
|
+
fleschReadingEase: 0,
|
|
2437
|
+
fleschKincaidGrade: 0,
|
|
2438
|
+
gunningFog: 0,
|
|
2439
|
+
readingLevel: "No text to score"
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
const avgWordsPerSentence = wordCount / sentenceCount2;
|
|
2443
|
+
const avgSyllablesPerWord = syllableCount2 / wordCount;
|
|
2444
|
+
const fleschReadingEase = round1(206.835 - 1.015 * avgWordsPerSentence - 84.6 * avgSyllablesPerWord);
|
|
2445
|
+
const fleschKincaidGrade = round1(0.39 * avgWordsPerSentence + 11.8 * avgSyllablesPerWord - 15.59);
|
|
2446
|
+
const gunningFog = round1(0.4 * (avgWordsPerSentence + 100 * (complexWordCount / wordCount)));
|
|
2447
|
+
return {
|
|
2448
|
+
wordCount,
|
|
2449
|
+
sentenceCount: sentences.length,
|
|
2450
|
+
syllableCount: syllableCount2,
|
|
2451
|
+
complexWordCount,
|
|
2452
|
+
avgWordsPerSentence: round1(avgWordsPerSentence),
|
|
2453
|
+
avgSyllablesPerWord: round1(avgSyllablesPerWord),
|
|
2454
|
+
fleschReadingEase,
|
|
2455
|
+
fleschKincaidGrade,
|
|
2456
|
+
gunningFog,
|
|
2457
|
+
readingLevel: readabilityGradeLabel(fleschReadingEase)
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2392
2460
|
|
|
2393
|
-
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectPassiveVoice, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, text_exports, unescapeString, wordFrequency };
|
|
2461
|
+
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectPassiveVoice, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, scoreReadability, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, text_exports, unescapeString, wordFrequency };
|
package/dist/index.cjs
CHANGED
|
@@ -1845,6 +1845,7 @@ __export(text_exports, {
|
|
|
1845
1845
|
readabilityScore: () => readabilityScore,
|
|
1846
1846
|
renderMarkdown: () => renderMarkdown,
|
|
1847
1847
|
romanToNumber: () => romanToNumber,
|
|
1848
|
+
scoreReadability: () => scoreReadability,
|
|
1848
1849
|
sentenceCount: () => sentenceCount,
|
|
1849
1850
|
slugify: () => slugify,
|
|
1850
1851
|
slugifyAll: () => slugifyAll,
|
|
@@ -4183,6 +4184,73 @@ function detectPassiveVoice(text) {
|
|
|
4183
4184
|
const passivePercent = totalSentences > 0 ? Math.round(passiveSentences / totalSentences * 1e3) / 10 : 0;
|
|
4184
4185
|
return { sentences: analyzed, totalSentences, passiveSentences, passivePercent };
|
|
4185
4186
|
}
|
|
4187
|
+
function countSyllables(word) {
|
|
4188
|
+
const w = word.toLowerCase().replace(/[^a-z]/g, "");
|
|
4189
|
+
if (w.length === 0) return 0;
|
|
4190
|
+
if (w.length <= 3) return 1;
|
|
4191
|
+
let count = 0;
|
|
4192
|
+
let prevWasVowel = false;
|
|
4193
|
+
for (const ch of w) {
|
|
4194
|
+
const isVowel = "aeiouy".includes(ch);
|
|
4195
|
+
if (isVowel && !prevWasVowel) count++;
|
|
4196
|
+
prevWasVowel = isVowel;
|
|
4197
|
+
}
|
|
4198
|
+
if (w.endsWith("e") && !w.endsWith("le") && count > 1) count--;
|
|
4199
|
+
if (w.endsWith("le") && w.length > 2 && !"aeiouy".includes(w[w.length - 3])) count++;
|
|
4200
|
+
return Math.max(count, 1);
|
|
4201
|
+
}
|
|
4202
|
+
function readabilityGradeLabel(fleschReadingEase) {
|
|
4203
|
+
if (fleschReadingEase >= 90) return "Very easy (5th grade)";
|
|
4204
|
+
if (fleschReadingEase >= 80) return "Easy (6th grade)";
|
|
4205
|
+
if (fleschReadingEase >= 70) return "Fairly easy (7th grade)";
|
|
4206
|
+
if (fleschReadingEase >= 60) return "Standard (8th-9th grade)";
|
|
4207
|
+
if (fleschReadingEase >= 50) return "Fairly difficult (10th-12th grade)";
|
|
4208
|
+
if (fleschReadingEase >= 30) return "Difficult (college)";
|
|
4209
|
+
return "Very difficult (college graduate)";
|
|
4210
|
+
}
|
|
4211
|
+
function round1(n) {
|
|
4212
|
+
return Math.round(n * 10) / 10;
|
|
4213
|
+
}
|
|
4214
|
+
function scoreReadability(text) {
|
|
4215
|
+
const sentences = splitIntoSentences(text);
|
|
4216
|
+
const words = text.match(/[a-zA-Z']+/g) ?? [];
|
|
4217
|
+
const sentenceCount2 = Math.max(sentences.length, 1);
|
|
4218
|
+
const wordCount = words.length;
|
|
4219
|
+
const syllableCounts = words.map(countSyllables);
|
|
4220
|
+
const syllableCount2 = syllableCounts.reduce((a, b) => a + b, 0);
|
|
4221
|
+
const complexWordCount = syllableCounts.filter((c) => c >= 3).length;
|
|
4222
|
+
if (wordCount === 0) {
|
|
4223
|
+
return {
|
|
4224
|
+
wordCount: 0,
|
|
4225
|
+
sentenceCount: 0,
|
|
4226
|
+
syllableCount: 0,
|
|
4227
|
+
complexWordCount: 0,
|
|
4228
|
+
avgWordsPerSentence: 0,
|
|
4229
|
+
avgSyllablesPerWord: 0,
|
|
4230
|
+
fleschReadingEase: 0,
|
|
4231
|
+
fleschKincaidGrade: 0,
|
|
4232
|
+
gunningFog: 0,
|
|
4233
|
+
readingLevel: "No text to score"
|
|
4234
|
+
};
|
|
4235
|
+
}
|
|
4236
|
+
const avgWordsPerSentence = wordCount / sentenceCount2;
|
|
4237
|
+
const avgSyllablesPerWord = syllableCount2 / wordCount;
|
|
4238
|
+
const fleschReadingEase = round1(206.835 - 1.015 * avgWordsPerSentence - 84.6 * avgSyllablesPerWord);
|
|
4239
|
+
const fleschKincaidGrade = round1(0.39 * avgWordsPerSentence + 11.8 * avgSyllablesPerWord - 15.59);
|
|
4240
|
+
const gunningFog = round1(0.4 * (avgWordsPerSentence + 100 * (complexWordCount / wordCount)));
|
|
4241
|
+
return {
|
|
4242
|
+
wordCount,
|
|
4243
|
+
sentenceCount: sentences.length,
|
|
4244
|
+
syllableCount: syllableCount2,
|
|
4245
|
+
complexWordCount,
|
|
4246
|
+
avgWordsPerSentence: round1(avgWordsPerSentence),
|
|
4247
|
+
avgSyllablesPerWord: round1(avgSyllablesPerWord),
|
|
4248
|
+
fleschReadingEase,
|
|
4249
|
+
fleschKincaidGrade,
|
|
4250
|
+
gunningFog,
|
|
4251
|
+
readingLevel: readabilityGradeLabel(fleschReadingEase)
|
|
4252
|
+
};
|
|
4253
|
+
}
|
|
4186
4254
|
|
|
4187
4255
|
// src/tools/data.ts
|
|
4188
4256
|
var data_exports = {};
|
|
@@ -16930,7 +16998,8 @@ var media_exports = {};
|
|
|
16930
16998
|
__export(media_exports, {
|
|
16931
16999
|
readExifData: () => readExifData,
|
|
16932
17000
|
readImageInfo: () => readImageInfo,
|
|
16933
|
-
readPdfMetadata: () => readPdfMetadata
|
|
17001
|
+
readPdfMetadata: () => readPdfMetadata,
|
|
17002
|
+
readWavInfo: () => readWavInfo
|
|
16934
17003
|
});
|
|
16935
17004
|
function readU32BE(bytes, offset) {
|
|
16936
17005
|
return (bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]) >>> 0;
|
|
@@ -17388,6 +17457,62 @@ function readPdfMetadata(bytes) {
|
|
|
17388
17457
|
encrypted
|
|
17389
17458
|
};
|
|
17390
17459
|
}
|
|
17460
|
+
var AUDIO_FORMAT_LABELS = {
|
|
17461
|
+
1: "PCM",
|
|
17462
|
+
3: "IEEE float",
|
|
17463
|
+
6: "A-law",
|
|
17464
|
+
7: "mu-law",
|
|
17465
|
+
65534: "Extensible"
|
|
17466
|
+
};
|
|
17467
|
+
function readAscii4(bytes, offset) {
|
|
17468
|
+
return String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
|
|
17469
|
+
}
|
|
17470
|
+
function readWavInfo(bytes) {
|
|
17471
|
+
if (bytes.length < 12) return { error: "File is too small to be a valid WAV file" };
|
|
17472
|
+
if (readAscii4(bytes, 0) !== "RIFF") return { error: 'Not a RIFF file (missing "RIFF" header)' };
|
|
17473
|
+
if (readAscii4(bytes, 8) !== "WAVE") return { error: 'Not a WAVE file (missing "WAVE" format marker)' };
|
|
17474
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
17475
|
+
const fileSize = view.getUint32(4, true) + 8;
|
|
17476
|
+
let offset = 12;
|
|
17477
|
+
let fmt = null;
|
|
17478
|
+
let dataSize = null;
|
|
17479
|
+
while (offset + 8 <= bytes.length) {
|
|
17480
|
+
const chunkId = readAscii4(bytes, offset);
|
|
17481
|
+
const chunkSize = view.getUint32(offset + 4, true);
|
|
17482
|
+
const dataOffset = offset + 8;
|
|
17483
|
+
if (chunkId === "fmt ") {
|
|
17484
|
+
if (dataOffset + 16 > bytes.length) return { error: 'Truncated "fmt " chunk' };
|
|
17485
|
+
fmt = {
|
|
17486
|
+
audioFormat: view.getUint16(dataOffset, true),
|
|
17487
|
+
channels: view.getUint16(dataOffset + 2, true),
|
|
17488
|
+
sampleRate: view.getUint32(dataOffset + 4, true),
|
|
17489
|
+
byteRate: view.getUint32(dataOffset + 8, true),
|
|
17490
|
+
blockAlign: view.getUint16(dataOffset + 12, true),
|
|
17491
|
+
bitsPerSample: view.getUint16(dataOffset + 14, true)
|
|
17492
|
+
};
|
|
17493
|
+
} else if (chunkId === "data") {
|
|
17494
|
+
dataSize = Math.min(chunkSize, bytes.length - dataOffset);
|
|
17495
|
+
}
|
|
17496
|
+
offset = dataOffset + chunkSize + chunkSize % 2;
|
|
17497
|
+
if (fmt && dataSize !== null) break;
|
|
17498
|
+
}
|
|
17499
|
+
if (!fmt) return { error: 'No "fmt " chunk found in this WAV file' };
|
|
17500
|
+
if (dataSize === null) return { error: 'No "data" chunk found in this WAV file' };
|
|
17501
|
+
if (fmt.byteRate <= 0) return { error: 'Invalid byte rate in "fmt " chunk' };
|
|
17502
|
+
const durationSeconds = Math.round(dataSize / fmt.byteRate * 1e3) / 1e3;
|
|
17503
|
+
return {
|
|
17504
|
+
audioFormat: fmt.audioFormat,
|
|
17505
|
+
audioFormatLabel: AUDIO_FORMAT_LABELS[fmt.audioFormat] ?? `Unknown (0x${fmt.audioFormat.toString(16)})`,
|
|
17506
|
+
channels: fmt.channels,
|
|
17507
|
+
sampleRate: fmt.sampleRate,
|
|
17508
|
+
byteRate: fmt.byteRate,
|
|
17509
|
+
blockAlign: fmt.blockAlign,
|
|
17510
|
+
bitsPerSample: fmt.bitsPerSample,
|
|
17511
|
+
dataSize,
|
|
17512
|
+
durationSeconds,
|
|
17513
|
+
fileSize
|
|
17514
|
+
};
|
|
17515
|
+
}
|
|
17391
17516
|
|
|
17392
17517
|
// src/index.ts
|
|
17393
17518
|
var version = "0.1.0";
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { j as json } from './json-BjSoIS1h.cjs';
|
|
2
2
|
export { e as encoding } from './encoding-7gmq-vkV.cjs';
|
|
3
3
|
export { h as hashing } from './hashing-CnetQFD_.cjs';
|
|
4
|
-
export { t as text } from './text-
|
|
4
|
+
export { t as text } from './text-Bbx-tZ43.cjs';
|
|
5
5
|
export { d as data } from './data-CakDxAcT.cjs';
|
|
6
6
|
export { g as generators } from './generators-BGtRGpJZ.cjs';
|
|
7
7
|
export { t as time } from './time-DbT8fjaF.cjs';
|
|
@@ -13,7 +13,7 @@ export { c as color } from './color-tPwZCr9H.cjs';
|
|
|
13
13
|
export { c as css } from './css-Cf7AMGM-.cjs';
|
|
14
14
|
export { m as misc } from './misc-CA3N198T.cjs';
|
|
15
15
|
export { a as ai_agent } from './ai_agent-CcpkV2DR.cjs';
|
|
16
|
-
export { m as media } from './media-
|
|
16
|
+
export { m as media } from './media-D66WnthC.cjs';
|
|
17
17
|
|
|
18
18
|
declare const version = "0.1.0";
|
|
19
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { j as json } from './json-BjSoIS1h.js';
|
|
2
2
|
export { e as encoding } from './encoding-7gmq-vkV.js';
|
|
3
3
|
export { h as hashing } from './hashing-CnetQFD_.js';
|
|
4
|
-
export { t as text } from './text-
|
|
4
|
+
export { t as text } from './text-Bbx-tZ43.js';
|
|
5
5
|
export { d as data } from './data-CakDxAcT.js';
|
|
6
6
|
export { g as generators } from './generators-BGtRGpJZ.js';
|
|
7
7
|
export { t as time } from './time-DbT8fjaF.js';
|
|
@@ -13,7 +13,7 @@ export { c as color } from './color-tPwZCr9H.js';
|
|
|
13
13
|
export { c as css } from './css-Cf7AMGM-.js';
|
|
14
14
|
export { m as misc } from './misc-CA3N198T.js';
|
|
15
15
|
export { a as ai_agent } from './ai_agent-CcpkV2DR.js';
|
|
16
|
-
export { m as media } from './media-
|
|
16
|
+
export { m as media } from './media-D66WnthC.js';
|
|
17
17
|
|
|
18
18
|
declare const version = "0.1.0";
|
|
19
19
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { media_exports as media } from './chunk-
|
|
1
|
+
export { media_exports as media } from './chunk-5CKOJXFU.js';
|
|
2
2
|
export { units_exports as units } from './chunk-QJE743LY.js';
|
|
3
3
|
export { network_exports as network } from './chunk-V5JKVDBA.js';
|
|
4
4
|
export { api_exports as api } from './chunk-Q3B3YWOA.js';
|
|
@@ -10,7 +10,7 @@ export { ai_agent_exports as ai_agent } from './chunk-M35VJETW.js';
|
|
|
10
10
|
export { json_exports as json } from './chunk-TSAGO3XP.js';
|
|
11
11
|
export { encoding_exports as encoding } from './chunk-IPR7FSX4.js';
|
|
12
12
|
export { hashing_exports as hashing } from './chunk-GEFVMGZR.js';
|
|
13
|
-
export { text_exports as text } from './chunk-
|
|
13
|
+
export { text_exports as text } from './chunk-F57WMKZO.js';
|
|
14
14
|
export { data_exports as data } from './chunk-DNCOIO5N.js';
|
|
15
15
|
export { generators_exports as generators } from './chunk-2CJSLYWI.js';
|
|
16
16
|
export { time_exports as time } from './chunk-ZPQZEIXP.js';
|
|
@@ -64,6 +64,28 @@ interface PdfMetadataError {
|
|
|
64
64
|
* pdf.js or other PDF rendering library required.
|
|
65
65
|
*/
|
|
66
66
|
declare function readPdfMetadata(bytes: Uint8Array): PdfMetadata | PdfMetadataError;
|
|
67
|
+
interface WavInfo {
|
|
68
|
+
audioFormat: number;
|
|
69
|
+
audioFormatLabel: string;
|
|
70
|
+
channels: number;
|
|
71
|
+
sampleRate: number;
|
|
72
|
+
byteRate: number;
|
|
73
|
+
blockAlign: number;
|
|
74
|
+
bitsPerSample: number;
|
|
75
|
+
dataSize: number;
|
|
76
|
+
durationSeconds: number;
|
|
77
|
+
fileSize: number;
|
|
78
|
+
}
|
|
79
|
+
interface WavInfoError {
|
|
80
|
+
error: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read a WAV file's RIFF/fmt/data chunk headers to report sample rate,
|
|
84
|
+
* channel count, bit depth, and duration, without decoding any audio
|
|
85
|
+
* samples. Only the canonical RIFF/WAVE container is supported (not the
|
|
86
|
+
* rarer RF64 variant used for files over 4GB).
|
|
87
|
+
*/
|
|
88
|
+
declare function readWavInfo(bytes: Uint8Array): WavInfo | WavInfoError;
|
|
67
89
|
|
|
68
90
|
type media_ExifData = ExifData;
|
|
69
91
|
type media_ExifError = ExifError;
|
|
@@ -72,11 +94,14 @@ type media_ImageInfo = ImageInfo;
|
|
|
72
94
|
type media_ImageInfoError = ImageInfoError;
|
|
73
95
|
type media_PdfMetadata = PdfMetadata;
|
|
74
96
|
type media_PdfMetadataError = PdfMetadataError;
|
|
97
|
+
type media_WavInfo = WavInfo;
|
|
98
|
+
type media_WavInfoError = WavInfoError;
|
|
75
99
|
declare const media_readExifData: typeof readExifData;
|
|
76
100
|
declare const media_readImageInfo: typeof readImageInfo;
|
|
77
101
|
declare const media_readPdfMetadata: typeof readPdfMetadata;
|
|
102
|
+
declare const media_readWavInfo: typeof readWavInfo;
|
|
78
103
|
declare namespace media {
|
|
79
|
-
export { type media_ExifData as ExifData, type media_ExifError as ExifError, type media_ImageFormat as ImageFormat, type media_ImageInfo as ImageInfo, type media_ImageInfoError as ImageInfoError, type media_PdfMetadata as PdfMetadata, type media_PdfMetadataError as PdfMetadataError, media_readExifData as readExifData, media_readImageInfo as readImageInfo, media_readPdfMetadata as readPdfMetadata };
|
|
104
|
+
export { type media_ExifData as ExifData, type media_ExifError as ExifError, type media_ImageFormat as ImageFormat, type media_ImageInfo as ImageInfo, type media_ImageInfoError as ImageInfoError, type media_PdfMetadata as PdfMetadata, type media_PdfMetadataError as PdfMetadataError, type media_WavInfo as WavInfo, type media_WavInfoError as WavInfoError, media_readExifData as readExifData, media_readImageInfo as readImageInfo, media_readPdfMetadata as readPdfMetadata, media_readWavInfo as readWavInfo };
|
|
80
105
|
}
|
|
81
106
|
|
|
82
|
-
export { type ExifData as E, type ImageFormat as I, type PdfMetadata as P, type ExifError as a, type ImageInfo as b, type ImageInfoError as c, type PdfMetadataError as d,
|
|
107
|
+
export { type ExifData as E, type ImageFormat as I, type PdfMetadata as P, type WavInfo as W, type ExifError as a, type ImageInfo as b, type ImageInfoError as c, type PdfMetadataError as d, type WavInfoError as e, readImageInfo as f, readPdfMetadata as g, readWavInfo as h, media as m, readExifData as r };
|
|
@@ -64,6 +64,28 @@ interface PdfMetadataError {
|
|
|
64
64
|
* pdf.js or other PDF rendering library required.
|
|
65
65
|
*/
|
|
66
66
|
declare function readPdfMetadata(bytes: Uint8Array): PdfMetadata | PdfMetadataError;
|
|
67
|
+
interface WavInfo {
|
|
68
|
+
audioFormat: number;
|
|
69
|
+
audioFormatLabel: string;
|
|
70
|
+
channels: number;
|
|
71
|
+
sampleRate: number;
|
|
72
|
+
byteRate: number;
|
|
73
|
+
blockAlign: number;
|
|
74
|
+
bitsPerSample: number;
|
|
75
|
+
dataSize: number;
|
|
76
|
+
durationSeconds: number;
|
|
77
|
+
fileSize: number;
|
|
78
|
+
}
|
|
79
|
+
interface WavInfoError {
|
|
80
|
+
error: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read a WAV file's RIFF/fmt/data chunk headers to report sample rate,
|
|
84
|
+
* channel count, bit depth, and duration, without decoding any audio
|
|
85
|
+
* samples. Only the canonical RIFF/WAVE container is supported (not the
|
|
86
|
+
* rarer RF64 variant used for files over 4GB).
|
|
87
|
+
*/
|
|
88
|
+
declare function readWavInfo(bytes: Uint8Array): WavInfo | WavInfoError;
|
|
67
89
|
|
|
68
90
|
type media_ExifData = ExifData;
|
|
69
91
|
type media_ExifError = ExifError;
|
|
@@ -72,11 +94,14 @@ type media_ImageInfo = ImageInfo;
|
|
|
72
94
|
type media_ImageInfoError = ImageInfoError;
|
|
73
95
|
type media_PdfMetadata = PdfMetadata;
|
|
74
96
|
type media_PdfMetadataError = PdfMetadataError;
|
|
97
|
+
type media_WavInfo = WavInfo;
|
|
98
|
+
type media_WavInfoError = WavInfoError;
|
|
75
99
|
declare const media_readExifData: typeof readExifData;
|
|
76
100
|
declare const media_readImageInfo: typeof readImageInfo;
|
|
77
101
|
declare const media_readPdfMetadata: typeof readPdfMetadata;
|
|
102
|
+
declare const media_readWavInfo: typeof readWavInfo;
|
|
78
103
|
declare namespace media {
|
|
79
|
-
export { type media_ExifData as ExifData, type media_ExifError as ExifError, type media_ImageFormat as ImageFormat, type media_ImageInfo as ImageInfo, type media_ImageInfoError as ImageInfoError, type media_PdfMetadata as PdfMetadata, type media_PdfMetadataError as PdfMetadataError, media_readExifData as readExifData, media_readImageInfo as readImageInfo, media_readPdfMetadata as readPdfMetadata };
|
|
104
|
+
export { type media_ExifData as ExifData, type media_ExifError as ExifError, type media_ImageFormat as ImageFormat, type media_ImageInfo as ImageInfo, type media_ImageInfoError as ImageInfoError, type media_PdfMetadata as PdfMetadata, type media_PdfMetadataError as PdfMetadataError, type media_WavInfo as WavInfo, type media_WavInfoError as WavInfoError, media_readExifData as readExifData, media_readImageInfo as readImageInfo, media_readPdfMetadata as readPdfMetadata, media_readWavInfo as readWavInfo };
|
|
80
105
|
}
|
|
81
106
|
|
|
82
|
-
export { type ExifData as E, type ImageFormat as I, type PdfMetadata as P, type ExifError as a, type ImageInfo as b, type ImageInfoError as c, type PdfMetadataError as d,
|
|
107
|
+
export { type ExifData as E, type ImageFormat as I, type PdfMetadata as P, type WavInfo as W, type ExifError as a, type ImageInfo as b, type ImageInfoError as c, type PdfMetadataError as d, type WavInfoError as e, readImageInfo as f, readPdfMetadata as g, readWavInfo as h, media as m, readExifData as r };
|
|
@@ -256,6 +256,25 @@ interface PassiveVoiceResult {
|
|
|
256
256
|
* "was written", "is being reviewed", "were quickly approved by the team".
|
|
257
257
|
*/
|
|
258
258
|
declare function detectPassiveVoice(text: string): PassiveVoiceResult;
|
|
259
|
+
interface ReadabilityResult {
|
|
260
|
+
wordCount: number;
|
|
261
|
+
sentenceCount: number;
|
|
262
|
+
syllableCount: number;
|
|
263
|
+
complexWordCount: number;
|
|
264
|
+
avgWordsPerSentence: number;
|
|
265
|
+
avgSyllablesPerWord: number;
|
|
266
|
+
fleschReadingEase: number;
|
|
267
|
+
fleschKincaidGrade: number;
|
|
268
|
+
gunningFog: number;
|
|
269
|
+
readingLevel: string;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Score pasted text with Flesch Reading Ease, Flesch-Kincaid Grade Level,
|
|
273
|
+
* and Gunning Fog Index, using a heuristic syllable counter (vowel-group
|
|
274
|
+
* counting with common English spelling adjustments) rather than a
|
|
275
|
+
* dictionary lookup, so scores are an estimate rather than exact.
|
|
276
|
+
*/
|
|
277
|
+
declare function scoreReadability(text: string): ReadabilityResult;
|
|
259
278
|
|
|
260
279
|
type text_AsciiFont = AsciiFont;
|
|
261
280
|
type text_AsciiOptions = AsciiOptions;
|
|
@@ -283,6 +302,7 @@ type text_ParsedTable = ParsedTable;
|
|
|
283
302
|
type text_PassiveVoiceMatch = PassiveVoiceMatch;
|
|
284
303
|
type text_PassiveVoiceResult = PassiveVoiceResult;
|
|
285
304
|
type text_PassiveVoiceSentence = PassiveVoiceSentence;
|
|
305
|
+
type text_ReadabilityResult = ReadabilityResult;
|
|
286
306
|
type text_ReadabilityScore = ReadabilityScore;
|
|
287
307
|
type text_SlugSeparator = SlugSeparator;
|
|
288
308
|
type text_TableOptions = TableOptions;
|
|
@@ -330,6 +350,7 @@ declare const text_parseTableData: typeof parseTableData;
|
|
|
330
350
|
declare const text_readabilityScore: typeof readabilityScore;
|
|
331
351
|
declare const text_renderMarkdown: typeof renderMarkdown;
|
|
332
352
|
declare const text_romanToNumber: typeof romanToNumber;
|
|
353
|
+
declare const text_scoreReadability: typeof scoreReadability;
|
|
333
354
|
declare const text_sentenceCount: typeof sentenceCount;
|
|
334
355
|
declare const text_slugify: typeof slugify;
|
|
335
356
|
declare const text_slugifyAll: typeof slugifyAll;
|
|
@@ -339,7 +360,7 @@ declare const text_textToMorse: typeof textToMorse;
|
|
|
339
360
|
declare const text_unescapeString: typeof unescapeString;
|
|
340
361
|
declare const text_wordFrequency: typeof wordFrequency;
|
|
341
362
|
declare namespace text {
|
|
342
|
-
export { type text_AsciiFont as AsciiFont, type text_AsciiOptions as AsciiOptions, text_CASE_FORMATS as CASE_FORMATS, type text_CaseFormat as CaseFormat, type text_ConvertOptions as ConvertOptions, text_DEFAULT_CONVERT_OPTIONS as DEFAULT_CONVERT_OPTIONS, type text_DiffFile as DiffFile, type text_DiffHunk as DiffHunk, type text_DiffLine as DiffLine, type text_DiffResult as DiffResult, type text_DiffType as DiffType, type text_DiffViewerLine as DiffViewerLine, text_ESCAPE_MODES as ESCAPE_MODES, type text_EscapeMode as EscapeMode, text_LINE_OPS as LINE_OPS, type text_LineOp as LineOp, type text_LineType as LineType, type text_LoremUnit as LoremUnit, text_MORSE_CODE as MORSE_CODE, type text_MarkdownResult as MarkdownResult, type text_MorseOptions as MorseOptions, type text_ParsedDiff as ParsedDiff, type text_ParsedTable as ParsedTable, type text_PassiveVoiceMatch as PassiveVoiceMatch, type text_PassiveVoiceResult as PassiveVoiceResult, type text_PassiveVoiceSentence as PassiveVoiceSentence, type text_ReadabilityScore as ReadabilityScore, type text_SlugSeparator as SlugSeparator, type text_TableOptions as TableOptions, type text_TextAnalysis as TextAnalysis, type text_WordCountResult as WordCountResult, text_addBorder as addBorder, text_analyzeText as analyzeText, text_applyOp as applyOp, text_applyOps as applyOps, text_centerText as centerText, text_convertAll as convertAll, text_convertCase as convertCase, text_countWords as countWords, text_csvToHtml as csvToHtml, text_csvToMarkdown as csvToMarkdown, text_detectDelimiter as detectDelimiter, text_detectPassiveVoice as detectPassiveVoice, text_diffLines as diffLines, text_diffLinesSimple as diffLinesSimple, text_diffStats as diffStats, text_escapeAll as escapeAll, text_escapeString as escapeString, text_extractHeadings as extractHeadings, text_formatReadingTime as formatReadingTime, text_generate as generate, text_generateDiff as generateDiff, text_generateHtmlTable as generateHtmlTable, text_generateMarkdownTable as generateMarkdownTable, text_generateParagraphs as generateParagraphs, text_generateSentences as generateSentences, text_generateWords as generateWords, text_getAvailableFonts as getAvailableFonts, text_getMorseForChar as getMorseForChar, text_getMorseTiming as getMorseTiming, text_htmlToMarkdown as htmlToMarkdown, text_isValidMorse as isValidMorse, text_markdownToHtml as markdownToHtml, text_morseToText as morseToText, text_numberToOrdinal as numberToOrdinal, text_numberToRoman as numberToRoman, text_numberToWords as numberToWords, text_ordinalWords as ordinalWords, text_parseDiff as parseDiff, text_parseTableData as parseTableData, text_readabilityScore as readabilityScore, text_renderMarkdown as renderMarkdown, text_romanToNumber as romanToNumber, text_sentenceCount as sentenceCount, text_slugify as slugify, text_slugifyAll as slugifyAll, text_syllableCount as syllableCount, text_textToAscii as textToAscii, text_textToMorse as textToMorse, text_unescapeString as unescapeString, text_wordFrequency as wordFrequency };
|
|
363
|
+
export { type text_AsciiFont as AsciiFont, type text_AsciiOptions as AsciiOptions, text_CASE_FORMATS as CASE_FORMATS, type text_CaseFormat as CaseFormat, type text_ConvertOptions as ConvertOptions, text_DEFAULT_CONVERT_OPTIONS as DEFAULT_CONVERT_OPTIONS, type text_DiffFile as DiffFile, type text_DiffHunk as DiffHunk, type text_DiffLine as DiffLine, type text_DiffResult as DiffResult, type text_DiffType as DiffType, type text_DiffViewerLine as DiffViewerLine, text_ESCAPE_MODES as ESCAPE_MODES, type text_EscapeMode as EscapeMode, text_LINE_OPS as LINE_OPS, type text_LineOp as LineOp, type text_LineType as LineType, type text_LoremUnit as LoremUnit, text_MORSE_CODE as MORSE_CODE, type text_MarkdownResult as MarkdownResult, type text_MorseOptions as MorseOptions, type text_ParsedDiff as ParsedDiff, type text_ParsedTable as ParsedTable, type text_PassiveVoiceMatch as PassiveVoiceMatch, type text_PassiveVoiceResult as PassiveVoiceResult, type text_PassiveVoiceSentence as PassiveVoiceSentence, type text_ReadabilityResult as ReadabilityResult, type text_ReadabilityScore as ReadabilityScore, type text_SlugSeparator as SlugSeparator, type text_TableOptions as TableOptions, type text_TextAnalysis as TextAnalysis, type text_WordCountResult as WordCountResult, text_addBorder as addBorder, text_analyzeText as analyzeText, text_applyOp as applyOp, text_applyOps as applyOps, text_centerText as centerText, text_convertAll as convertAll, text_convertCase as convertCase, text_countWords as countWords, text_csvToHtml as csvToHtml, text_csvToMarkdown as csvToMarkdown, text_detectDelimiter as detectDelimiter, text_detectPassiveVoice as detectPassiveVoice, text_diffLines as diffLines, text_diffLinesSimple as diffLinesSimple, text_diffStats as diffStats, text_escapeAll as escapeAll, text_escapeString as escapeString, text_extractHeadings as extractHeadings, text_formatReadingTime as formatReadingTime, text_generate as generate, text_generateDiff as generateDiff, text_generateHtmlTable as generateHtmlTable, text_generateMarkdownTable as generateMarkdownTable, text_generateParagraphs as generateParagraphs, text_generateSentences as generateSentences, text_generateWords as generateWords, text_getAvailableFonts as getAvailableFonts, text_getMorseForChar as getMorseForChar, text_getMorseTiming as getMorseTiming, text_htmlToMarkdown as htmlToMarkdown, text_isValidMorse as isValidMorse, text_markdownToHtml as markdownToHtml, text_morseToText as morseToText, text_numberToOrdinal as numberToOrdinal, text_numberToRoman as numberToRoman, text_numberToWords as numberToWords, text_ordinalWords as ordinalWords, text_parseDiff as parseDiff, text_parseTableData as parseTableData, text_readabilityScore as readabilityScore, text_renderMarkdown as renderMarkdown, text_romanToNumber as romanToNumber, text_scoreReadability as scoreReadability, text_sentenceCount as sentenceCount, text_slugify as slugify, text_slugifyAll as slugifyAll, text_syllableCount as syllableCount, text_textToAscii as textToAscii, text_textToMorse as textToMorse, text_unescapeString as unescapeString, text_wordFrequency as wordFrequency };
|
|
343
364
|
}
|
|
344
365
|
|
|
345
|
-
export {
|
|
366
|
+
export { generateDiff as $, type AsciiFont as A, centerText as B, CASE_FORMATS as C, DEFAULT_CONVERT_OPTIONS as D, ESCAPE_MODES as E, convertAll as F, convertCase as G, countWords as H, csvToHtml as I, csvToMarkdown as J, detectDelimiter as K, LINE_OPS as L, MORSE_CODE as M, detectPassiveVoice as N, diffLines as O, type ParsedDiff as P, diffLinesSimple as Q, type ReadabilityResult as R, type SlugSeparator as S, type TableOptions as T, diffStats as U, escapeAll as V, type WordCountResult as W, escapeString as X, extractHeadings as Y, formatReadingTime as Z, generate as _, type AsciiOptions as a, generateHtmlTable as a0, generateMarkdownTable as a1, generateParagraphs as a2, generateSentences as a3, generateWords as a4, getAvailableFonts as a5, getMorseForChar as a6, getMorseTiming as a7, htmlToMarkdown as a8, isValidMorse as a9, markdownToHtml as aa, morseToText as ab, numberToOrdinal as ac, numberToRoman as ad, numberToWords as ae, ordinalWords as af, parseDiff as ag, parseTableData as ah, readabilityScore as ai, renderMarkdown as aj, romanToNumber as ak, scoreReadability as al, sentenceCount as am, slugify as an, slugifyAll as ao, syllableCount as ap, textToAscii as aq, textToMorse as ar, unescapeString as as, wordFrequency as at, type CaseFormat as b, type ConvertOptions as c, type DiffFile as d, type DiffHunk as e, type DiffLine as f, type DiffResult as g, type DiffType as h, type DiffViewerLine as i, type EscapeMode as j, type LineOp as k, type LineType as l, type LoremUnit as m, type MarkdownResult as n, type MorseOptions as o, type ParsedTable as p, type PassiveVoiceMatch as q, type PassiveVoiceResult as r, type PassiveVoiceSentence as s, text as t, type ReadabilityScore as u, type TextAnalysis as v, addBorder as w, analyzeText as x, applyOp as y, applyOps as z };
|
|
@@ -256,6 +256,25 @@ interface PassiveVoiceResult {
|
|
|
256
256
|
* "was written", "is being reviewed", "were quickly approved by the team".
|
|
257
257
|
*/
|
|
258
258
|
declare function detectPassiveVoice(text: string): PassiveVoiceResult;
|
|
259
|
+
interface ReadabilityResult {
|
|
260
|
+
wordCount: number;
|
|
261
|
+
sentenceCount: number;
|
|
262
|
+
syllableCount: number;
|
|
263
|
+
complexWordCount: number;
|
|
264
|
+
avgWordsPerSentence: number;
|
|
265
|
+
avgSyllablesPerWord: number;
|
|
266
|
+
fleschReadingEase: number;
|
|
267
|
+
fleschKincaidGrade: number;
|
|
268
|
+
gunningFog: number;
|
|
269
|
+
readingLevel: string;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Score pasted text with Flesch Reading Ease, Flesch-Kincaid Grade Level,
|
|
273
|
+
* and Gunning Fog Index, using a heuristic syllable counter (vowel-group
|
|
274
|
+
* counting with common English spelling adjustments) rather than a
|
|
275
|
+
* dictionary lookup, so scores are an estimate rather than exact.
|
|
276
|
+
*/
|
|
277
|
+
declare function scoreReadability(text: string): ReadabilityResult;
|
|
259
278
|
|
|
260
279
|
type text_AsciiFont = AsciiFont;
|
|
261
280
|
type text_AsciiOptions = AsciiOptions;
|
|
@@ -283,6 +302,7 @@ type text_ParsedTable = ParsedTable;
|
|
|
283
302
|
type text_PassiveVoiceMatch = PassiveVoiceMatch;
|
|
284
303
|
type text_PassiveVoiceResult = PassiveVoiceResult;
|
|
285
304
|
type text_PassiveVoiceSentence = PassiveVoiceSentence;
|
|
305
|
+
type text_ReadabilityResult = ReadabilityResult;
|
|
286
306
|
type text_ReadabilityScore = ReadabilityScore;
|
|
287
307
|
type text_SlugSeparator = SlugSeparator;
|
|
288
308
|
type text_TableOptions = TableOptions;
|
|
@@ -330,6 +350,7 @@ declare const text_parseTableData: typeof parseTableData;
|
|
|
330
350
|
declare const text_readabilityScore: typeof readabilityScore;
|
|
331
351
|
declare const text_renderMarkdown: typeof renderMarkdown;
|
|
332
352
|
declare const text_romanToNumber: typeof romanToNumber;
|
|
353
|
+
declare const text_scoreReadability: typeof scoreReadability;
|
|
333
354
|
declare const text_sentenceCount: typeof sentenceCount;
|
|
334
355
|
declare const text_slugify: typeof slugify;
|
|
335
356
|
declare const text_slugifyAll: typeof slugifyAll;
|
|
@@ -339,7 +360,7 @@ declare const text_textToMorse: typeof textToMorse;
|
|
|
339
360
|
declare const text_unescapeString: typeof unescapeString;
|
|
340
361
|
declare const text_wordFrequency: typeof wordFrequency;
|
|
341
362
|
declare namespace text {
|
|
342
|
-
export { type text_AsciiFont as AsciiFont, type text_AsciiOptions as AsciiOptions, text_CASE_FORMATS as CASE_FORMATS, type text_CaseFormat as CaseFormat, type text_ConvertOptions as ConvertOptions, text_DEFAULT_CONVERT_OPTIONS as DEFAULT_CONVERT_OPTIONS, type text_DiffFile as DiffFile, type text_DiffHunk as DiffHunk, type text_DiffLine as DiffLine, type text_DiffResult as DiffResult, type text_DiffType as DiffType, type text_DiffViewerLine as DiffViewerLine, text_ESCAPE_MODES as ESCAPE_MODES, type text_EscapeMode as EscapeMode, text_LINE_OPS as LINE_OPS, type text_LineOp as LineOp, type text_LineType as LineType, type text_LoremUnit as LoremUnit, text_MORSE_CODE as MORSE_CODE, type text_MarkdownResult as MarkdownResult, type text_MorseOptions as MorseOptions, type text_ParsedDiff as ParsedDiff, type text_ParsedTable as ParsedTable, type text_PassiveVoiceMatch as PassiveVoiceMatch, type text_PassiveVoiceResult as PassiveVoiceResult, type text_PassiveVoiceSentence as PassiveVoiceSentence, type text_ReadabilityScore as ReadabilityScore, type text_SlugSeparator as SlugSeparator, type text_TableOptions as TableOptions, type text_TextAnalysis as TextAnalysis, type text_WordCountResult as WordCountResult, text_addBorder as addBorder, text_analyzeText as analyzeText, text_applyOp as applyOp, text_applyOps as applyOps, text_centerText as centerText, text_convertAll as convertAll, text_convertCase as convertCase, text_countWords as countWords, text_csvToHtml as csvToHtml, text_csvToMarkdown as csvToMarkdown, text_detectDelimiter as detectDelimiter, text_detectPassiveVoice as detectPassiveVoice, text_diffLines as diffLines, text_diffLinesSimple as diffLinesSimple, text_diffStats as diffStats, text_escapeAll as escapeAll, text_escapeString as escapeString, text_extractHeadings as extractHeadings, text_formatReadingTime as formatReadingTime, text_generate as generate, text_generateDiff as generateDiff, text_generateHtmlTable as generateHtmlTable, text_generateMarkdownTable as generateMarkdownTable, text_generateParagraphs as generateParagraphs, text_generateSentences as generateSentences, text_generateWords as generateWords, text_getAvailableFonts as getAvailableFonts, text_getMorseForChar as getMorseForChar, text_getMorseTiming as getMorseTiming, text_htmlToMarkdown as htmlToMarkdown, text_isValidMorse as isValidMorse, text_markdownToHtml as markdownToHtml, text_morseToText as morseToText, text_numberToOrdinal as numberToOrdinal, text_numberToRoman as numberToRoman, text_numberToWords as numberToWords, text_ordinalWords as ordinalWords, text_parseDiff as parseDiff, text_parseTableData as parseTableData, text_readabilityScore as readabilityScore, text_renderMarkdown as renderMarkdown, text_romanToNumber as romanToNumber, text_sentenceCount as sentenceCount, text_slugify as slugify, text_slugifyAll as slugifyAll, text_syllableCount as syllableCount, text_textToAscii as textToAscii, text_textToMorse as textToMorse, text_unescapeString as unescapeString, text_wordFrequency as wordFrequency };
|
|
363
|
+
export { type text_AsciiFont as AsciiFont, type text_AsciiOptions as AsciiOptions, text_CASE_FORMATS as CASE_FORMATS, type text_CaseFormat as CaseFormat, type text_ConvertOptions as ConvertOptions, text_DEFAULT_CONVERT_OPTIONS as DEFAULT_CONVERT_OPTIONS, type text_DiffFile as DiffFile, type text_DiffHunk as DiffHunk, type text_DiffLine as DiffLine, type text_DiffResult as DiffResult, type text_DiffType as DiffType, type text_DiffViewerLine as DiffViewerLine, text_ESCAPE_MODES as ESCAPE_MODES, type text_EscapeMode as EscapeMode, text_LINE_OPS as LINE_OPS, type text_LineOp as LineOp, type text_LineType as LineType, type text_LoremUnit as LoremUnit, text_MORSE_CODE as MORSE_CODE, type text_MarkdownResult as MarkdownResult, type text_MorseOptions as MorseOptions, type text_ParsedDiff as ParsedDiff, type text_ParsedTable as ParsedTable, type text_PassiveVoiceMatch as PassiveVoiceMatch, type text_PassiveVoiceResult as PassiveVoiceResult, type text_PassiveVoiceSentence as PassiveVoiceSentence, type text_ReadabilityResult as ReadabilityResult, type text_ReadabilityScore as ReadabilityScore, type text_SlugSeparator as SlugSeparator, type text_TableOptions as TableOptions, type text_TextAnalysis as TextAnalysis, type text_WordCountResult as WordCountResult, text_addBorder as addBorder, text_analyzeText as analyzeText, text_applyOp as applyOp, text_applyOps as applyOps, text_centerText as centerText, text_convertAll as convertAll, text_convertCase as convertCase, text_countWords as countWords, text_csvToHtml as csvToHtml, text_csvToMarkdown as csvToMarkdown, text_detectDelimiter as detectDelimiter, text_detectPassiveVoice as detectPassiveVoice, text_diffLines as diffLines, text_diffLinesSimple as diffLinesSimple, text_diffStats as diffStats, text_escapeAll as escapeAll, text_escapeString as escapeString, text_extractHeadings as extractHeadings, text_formatReadingTime as formatReadingTime, text_generate as generate, text_generateDiff as generateDiff, text_generateHtmlTable as generateHtmlTable, text_generateMarkdownTable as generateMarkdownTable, text_generateParagraphs as generateParagraphs, text_generateSentences as generateSentences, text_generateWords as generateWords, text_getAvailableFonts as getAvailableFonts, text_getMorseForChar as getMorseForChar, text_getMorseTiming as getMorseTiming, text_htmlToMarkdown as htmlToMarkdown, text_isValidMorse as isValidMorse, text_markdownToHtml as markdownToHtml, text_morseToText as morseToText, text_numberToOrdinal as numberToOrdinal, text_numberToRoman as numberToRoman, text_numberToWords as numberToWords, text_ordinalWords as ordinalWords, text_parseDiff as parseDiff, text_parseTableData as parseTableData, text_readabilityScore as readabilityScore, text_renderMarkdown as renderMarkdown, text_romanToNumber as romanToNumber, text_scoreReadability as scoreReadability, text_sentenceCount as sentenceCount, text_slugify as slugify, text_slugifyAll as slugifyAll, text_syllableCount as syllableCount, text_textToAscii as textToAscii, text_textToMorse as textToMorse, text_unescapeString as unescapeString, text_wordFrequency as wordFrequency };
|
|
343
364
|
}
|
|
344
365
|
|
|
345
|
-
export {
|
|
366
|
+
export { generateDiff as $, type AsciiFont as A, centerText as B, CASE_FORMATS as C, DEFAULT_CONVERT_OPTIONS as D, ESCAPE_MODES as E, convertAll as F, convertCase as G, countWords as H, csvToHtml as I, csvToMarkdown as J, detectDelimiter as K, LINE_OPS as L, MORSE_CODE as M, detectPassiveVoice as N, diffLines as O, type ParsedDiff as P, diffLinesSimple as Q, type ReadabilityResult as R, type SlugSeparator as S, type TableOptions as T, diffStats as U, escapeAll as V, type WordCountResult as W, escapeString as X, extractHeadings as Y, formatReadingTime as Z, generate as _, type AsciiOptions as a, generateHtmlTable as a0, generateMarkdownTable as a1, generateParagraphs as a2, generateSentences as a3, generateWords as a4, getAvailableFonts as a5, getMorseForChar as a6, getMorseTiming as a7, htmlToMarkdown as a8, isValidMorse as a9, markdownToHtml as aa, morseToText as ab, numberToOrdinal as ac, numberToRoman as ad, numberToWords as ae, ordinalWords as af, parseDiff as ag, parseTableData as ah, readabilityScore as ai, renderMarkdown as aj, romanToNumber as ak, scoreReadability as al, sentenceCount as am, slugify as an, slugifyAll as ao, syllableCount as ap, textToAscii as aq, textToMorse as ar, unescapeString as as, wordFrequency as at, type CaseFormat as b, type ConvertOptions as c, type DiffFile as d, type DiffHunk as e, type DiffLine as f, type DiffResult as g, type DiffType as h, type DiffViewerLine as i, type EscapeMode as j, type LineOp as k, type LineType as l, type LoremUnit as m, type MarkdownResult as n, type MorseOptions as o, type ParsedTable as p, type PassiveVoiceMatch as q, type PassiveVoiceResult as r, type PassiveVoiceSentence as s, text as t, type ReadabilityScore as u, type TextAnalysis as v, addBorder as w, analyzeText as x, applyOp as y, applyOps as z };
|
package/dist/tools/media.cjs
CHANGED
|
@@ -457,7 +457,64 @@ function readPdfMetadata(bytes) {
|
|
|
457
457
|
encrypted
|
|
458
458
|
};
|
|
459
459
|
}
|
|
460
|
+
var AUDIO_FORMAT_LABELS = {
|
|
461
|
+
1: "PCM",
|
|
462
|
+
3: "IEEE float",
|
|
463
|
+
6: "A-law",
|
|
464
|
+
7: "mu-law",
|
|
465
|
+
65534: "Extensible"
|
|
466
|
+
};
|
|
467
|
+
function readAscii4(bytes, offset) {
|
|
468
|
+
return String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
|
|
469
|
+
}
|
|
470
|
+
function readWavInfo(bytes) {
|
|
471
|
+
if (bytes.length < 12) return { error: "File is too small to be a valid WAV file" };
|
|
472
|
+
if (readAscii4(bytes, 0) !== "RIFF") return { error: 'Not a RIFF file (missing "RIFF" header)' };
|
|
473
|
+
if (readAscii4(bytes, 8) !== "WAVE") return { error: 'Not a WAVE file (missing "WAVE" format marker)' };
|
|
474
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
475
|
+
const fileSize = view.getUint32(4, true) + 8;
|
|
476
|
+
let offset = 12;
|
|
477
|
+
let fmt = null;
|
|
478
|
+
let dataSize = null;
|
|
479
|
+
while (offset + 8 <= bytes.length) {
|
|
480
|
+
const chunkId = readAscii4(bytes, offset);
|
|
481
|
+
const chunkSize = view.getUint32(offset + 4, true);
|
|
482
|
+
const dataOffset = offset + 8;
|
|
483
|
+
if (chunkId === "fmt ") {
|
|
484
|
+
if (dataOffset + 16 > bytes.length) return { error: 'Truncated "fmt " chunk' };
|
|
485
|
+
fmt = {
|
|
486
|
+
audioFormat: view.getUint16(dataOffset, true),
|
|
487
|
+
channels: view.getUint16(dataOffset + 2, true),
|
|
488
|
+
sampleRate: view.getUint32(dataOffset + 4, true),
|
|
489
|
+
byteRate: view.getUint32(dataOffset + 8, true),
|
|
490
|
+
blockAlign: view.getUint16(dataOffset + 12, true),
|
|
491
|
+
bitsPerSample: view.getUint16(dataOffset + 14, true)
|
|
492
|
+
};
|
|
493
|
+
} else if (chunkId === "data") {
|
|
494
|
+
dataSize = Math.min(chunkSize, bytes.length - dataOffset);
|
|
495
|
+
}
|
|
496
|
+
offset = dataOffset + chunkSize + chunkSize % 2;
|
|
497
|
+
if (fmt && dataSize !== null) break;
|
|
498
|
+
}
|
|
499
|
+
if (!fmt) return { error: 'No "fmt " chunk found in this WAV file' };
|
|
500
|
+
if (dataSize === null) return { error: 'No "data" chunk found in this WAV file' };
|
|
501
|
+
if (fmt.byteRate <= 0) return { error: 'Invalid byte rate in "fmt " chunk' };
|
|
502
|
+
const durationSeconds = Math.round(dataSize / fmt.byteRate * 1e3) / 1e3;
|
|
503
|
+
return {
|
|
504
|
+
audioFormat: fmt.audioFormat,
|
|
505
|
+
audioFormatLabel: AUDIO_FORMAT_LABELS[fmt.audioFormat] ?? `Unknown (0x${fmt.audioFormat.toString(16)})`,
|
|
506
|
+
channels: fmt.channels,
|
|
507
|
+
sampleRate: fmt.sampleRate,
|
|
508
|
+
byteRate: fmt.byteRate,
|
|
509
|
+
blockAlign: fmt.blockAlign,
|
|
510
|
+
bitsPerSample: fmt.bitsPerSample,
|
|
511
|
+
dataSize,
|
|
512
|
+
durationSeconds,
|
|
513
|
+
fileSize
|
|
514
|
+
};
|
|
515
|
+
}
|
|
460
516
|
|
|
461
517
|
exports.readExifData = readExifData;
|
|
462
518
|
exports.readImageInfo = readImageInfo;
|
|
463
519
|
exports.readPdfMetadata = readPdfMetadata;
|
|
520
|
+
exports.readWavInfo = readWavInfo;
|
package/dist/tools/media.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { E as ExifData, a as ExifError, I as ImageFormat, b as ImageInfo, c as ImageInfoError, P as PdfMetadata, d as PdfMetadataError, r as readExifData,
|
|
1
|
+
export { E as ExifData, a as ExifError, I as ImageFormat, b as ImageInfo, c as ImageInfoError, P as PdfMetadata, d as PdfMetadataError, W as WavInfo, e as WavInfoError, r as readExifData, f as readImageInfo, g as readPdfMetadata, h as readWavInfo } from '../media-D66WnthC.cjs';
|
package/dist/tools/media.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { E as ExifData, a as ExifError, I as ImageFormat, b as ImageInfo, c as ImageInfoError, P as PdfMetadata, d as PdfMetadataError, r as readExifData,
|
|
1
|
+
export { E as ExifData, a as ExifError, I as ImageFormat, b as ImageInfo, c as ImageInfoError, P as PdfMetadata, d as PdfMetadataError, W as WavInfo, e as WavInfoError, r as readExifData, f as readImageInfo, g as readPdfMetadata, h as readWavInfo } from '../media-D66WnthC.js';
|
package/dist/tools/media.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { readExifData, readImageInfo, readPdfMetadata } from '../chunk-
|
|
1
|
+
export { readExifData, readImageInfo, readPdfMetadata, readWavInfo } from '../chunk-5CKOJXFU.js';
|
|
2
2
|
import '../chunk-MLKGABMK.js';
|
package/dist/tools/text.cjs
CHANGED
|
@@ -2332,6 +2332,73 @@ function detectPassiveVoice(text) {
|
|
|
2332
2332
|
const passivePercent = totalSentences > 0 ? Math.round(passiveSentences / totalSentences * 1e3) / 10 : 0;
|
|
2333
2333
|
return { sentences: analyzed, totalSentences, passiveSentences, passivePercent };
|
|
2334
2334
|
}
|
|
2335
|
+
function countSyllables(word) {
|
|
2336
|
+
const w = word.toLowerCase().replace(/[^a-z]/g, "");
|
|
2337
|
+
if (w.length === 0) return 0;
|
|
2338
|
+
if (w.length <= 3) return 1;
|
|
2339
|
+
let count = 0;
|
|
2340
|
+
let prevWasVowel = false;
|
|
2341
|
+
for (const ch of w) {
|
|
2342
|
+
const isVowel = "aeiouy".includes(ch);
|
|
2343
|
+
if (isVowel && !prevWasVowel) count++;
|
|
2344
|
+
prevWasVowel = isVowel;
|
|
2345
|
+
}
|
|
2346
|
+
if (w.endsWith("e") && !w.endsWith("le") && count > 1) count--;
|
|
2347
|
+
if (w.endsWith("le") && w.length > 2 && !"aeiouy".includes(w[w.length - 3])) count++;
|
|
2348
|
+
return Math.max(count, 1);
|
|
2349
|
+
}
|
|
2350
|
+
function readabilityGradeLabel(fleschReadingEase) {
|
|
2351
|
+
if (fleschReadingEase >= 90) return "Very easy (5th grade)";
|
|
2352
|
+
if (fleschReadingEase >= 80) return "Easy (6th grade)";
|
|
2353
|
+
if (fleschReadingEase >= 70) return "Fairly easy (7th grade)";
|
|
2354
|
+
if (fleschReadingEase >= 60) return "Standard (8th-9th grade)";
|
|
2355
|
+
if (fleschReadingEase >= 50) return "Fairly difficult (10th-12th grade)";
|
|
2356
|
+
if (fleschReadingEase >= 30) return "Difficult (college)";
|
|
2357
|
+
return "Very difficult (college graduate)";
|
|
2358
|
+
}
|
|
2359
|
+
function round1(n) {
|
|
2360
|
+
return Math.round(n * 10) / 10;
|
|
2361
|
+
}
|
|
2362
|
+
function scoreReadability(text) {
|
|
2363
|
+
const sentences = splitIntoSentences(text);
|
|
2364
|
+
const words = text.match(/[a-zA-Z']+/g) ?? [];
|
|
2365
|
+
const sentenceCount2 = Math.max(sentences.length, 1);
|
|
2366
|
+
const wordCount = words.length;
|
|
2367
|
+
const syllableCounts = words.map(countSyllables);
|
|
2368
|
+
const syllableCount2 = syllableCounts.reduce((a, b) => a + b, 0);
|
|
2369
|
+
const complexWordCount = syllableCounts.filter((c) => c >= 3).length;
|
|
2370
|
+
if (wordCount === 0) {
|
|
2371
|
+
return {
|
|
2372
|
+
wordCount: 0,
|
|
2373
|
+
sentenceCount: 0,
|
|
2374
|
+
syllableCount: 0,
|
|
2375
|
+
complexWordCount: 0,
|
|
2376
|
+
avgWordsPerSentence: 0,
|
|
2377
|
+
avgSyllablesPerWord: 0,
|
|
2378
|
+
fleschReadingEase: 0,
|
|
2379
|
+
fleschKincaidGrade: 0,
|
|
2380
|
+
gunningFog: 0,
|
|
2381
|
+
readingLevel: "No text to score"
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
const avgWordsPerSentence = wordCount / sentenceCount2;
|
|
2385
|
+
const avgSyllablesPerWord = syllableCount2 / wordCount;
|
|
2386
|
+
const fleschReadingEase = round1(206.835 - 1.015 * avgWordsPerSentence - 84.6 * avgSyllablesPerWord);
|
|
2387
|
+
const fleschKincaidGrade = round1(0.39 * avgWordsPerSentence + 11.8 * avgSyllablesPerWord - 15.59);
|
|
2388
|
+
const gunningFog = round1(0.4 * (avgWordsPerSentence + 100 * (complexWordCount / wordCount)));
|
|
2389
|
+
return {
|
|
2390
|
+
wordCount,
|
|
2391
|
+
sentenceCount: sentences.length,
|
|
2392
|
+
syllableCount: syllableCount2,
|
|
2393
|
+
complexWordCount,
|
|
2394
|
+
avgWordsPerSentence: round1(avgWordsPerSentence),
|
|
2395
|
+
avgSyllablesPerWord: round1(avgSyllablesPerWord),
|
|
2396
|
+
fleschReadingEase,
|
|
2397
|
+
fleschKincaidGrade,
|
|
2398
|
+
gunningFog,
|
|
2399
|
+
readingLevel: readabilityGradeLabel(fleschReadingEase)
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2335
2402
|
|
|
2336
2403
|
exports.CASE_FORMATS = CASE_FORMATS;
|
|
2337
2404
|
exports.DEFAULT_CONVERT_OPTIONS = DEFAULT_CONVERT_OPTIONS;
|
|
@@ -2380,6 +2447,7 @@ exports.parseTableData = parseTableData;
|
|
|
2380
2447
|
exports.readabilityScore = readabilityScore;
|
|
2381
2448
|
exports.renderMarkdown = renderMarkdown;
|
|
2382
2449
|
exports.romanToNumber = romanToNumber;
|
|
2450
|
+
exports.scoreReadability = scoreReadability;
|
|
2383
2451
|
exports.sentenceCount = sentenceCount;
|
|
2384
2452
|
exports.slugify = slugify;
|
|
2385
2453
|
exports.slugifyAll = slugifyAll;
|
package/dist/tools/text.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityScore, S as SlugSeparator, T as TableOptions,
|
|
1
|
+
export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityResult, u as ReadabilityScore, S as SlugSeparator, T as TableOptions, v as TextAnalysis, W as WordCountResult, w as addBorder, x as analyzeText, y as applyOp, z as applyOps, B as centerText, F as convertAll, G as convertCase, H as countWords, I as csvToHtml, J as csvToMarkdown, K as detectDelimiter, N as detectPassiveVoice, O as diffLines, Q as diffLinesSimple, U as diffStats, V as escapeAll, X as escapeString, Y as extractHeadings, Z as formatReadingTime, _ as generate, $ as generateDiff, a0 as generateHtmlTable, a1 as generateMarkdownTable, a2 as generateParagraphs, a3 as generateSentences, a4 as generateWords, a5 as getAvailableFonts, a6 as getMorseForChar, a7 as getMorseTiming, a8 as htmlToMarkdown, a9 as isValidMorse, aa as markdownToHtml, ab as morseToText, ac as numberToOrdinal, ad as numberToRoman, ae as numberToWords, af as ordinalWords, ag as parseDiff, ah as parseTableData, ai as readabilityScore, aj as renderMarkdown, ak as romanToNumber, al as scoreReadability, am as sentenceCount, an as slugify, ao as slugifyAll, ap as syllableCount, aq as textToAscii, ar as textToMorse, as as unescapeString, at as wordFrequency } from '../text-Bbx-tZ43.cjs';
|
package/dist/tools/text.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityScore, S as SlugSeparator, T as TableOptions,
|
|
1
|
+
export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityResult, u as ReadabilityScore, S as SlugSeparator, T as TableOptions, v as TextAnalysis, W as WordCountResult, w as addBorder, x as analyzeText, y as applyOp, z as applyOps, B as centerText, F as convertAll, G as convertCase, H as countWords, I as csvToHtml, J as csvToMarkdown, K as detectDelimiter, N as detectPassiveVoice, O as diffLines, Q as diffLinesSimple, U as diffStats, V as escapeAll, X as escapeString, Y as extractHeadings, Z as formatReadingTime, _ as generate, $ as generateDiff, a0 as generateHtmlTable, a1 as generateMarkdownTable, a2 as generateParagraphs, a3 as generateSentences, a4 as generateWords, a5 as getAvailableFonts, a6 as getMorseForChar, a7 as getMorseTiming, a8 as htmlToMarkdown, a9 as isValidMorse, aa as markdownToHtml, ab as morseToText, ac as numberToOrdinal, ad as numberToRoman, ae as numberToWords, af as ordinalWords, ag as parseDiff, ah as parseTableData, ai as readabilityScore, aj as renderMarkdown, ak as romanToNumber, al as scoreReadability, am as sentenceCount, an as slugify, ao as slugifyAll, ap as syllableCount, aq as textToAscii, ar as textToMorse, as as unescapeString, at as wordFrequency } from '../text-Bbx-tZ43.js';
|
package/dist/tools/text.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectPassiveVoice, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, unescapeString, wordFrequency } from '../chunk-
|
|
1
|
+
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectPassiveVoice, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, scoreReadability, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, unescapeString, wordFrequency } from '../chunk-F57WMKZO.js';
|
|
2
2
|
import '../chunk-MLKGABMK.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utilix-tech/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "140+ developer utility tools for Node.js: JSON, encoding, hashing, color, CSS, network and more. Runs locally, no API key required.",
|
|
5
5
|
"author": "Utilix <hello@utilix.tech>",
|
|
6
6
|
"license": "MIT",
|