@promptbook/website-crawler 0.88.0-9 → 0.89.0-1
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 +35 -14
- package/esm/index.es.js +62 -26
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- package/esm/typings/src/playground/BrjappConnector.d.ts +64 -0
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
- package/esm/typings/src/playground/playground.d.ts +5 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +65 -29
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
|
|
|
58
58
|
|
|
59
59
|
During the computer revolution, we have seen [multiple generations of computer languages](https://github.com/webgptorg/promptbook/discussions/180), from the physical rewiring of the vacuum tubes through low-level machine code to the high-level languages like Python or JavaScript. And now, we're on the edge of the **next revolution**!
|
|
60
60
|
|
|
61
|
+
|
|
62
|
+
|
|
61
63
|
It's a revolution of writing software in **plain human language** that is understandable and executable by both humans and machines – and it's going to change everything!
|
|
62
64
|
|
|
63
65
|
The incredible growth in power of microprocessors and the Moore's Law have been the driving force behind the ever-more powerful languages, and it's been an amazing journey! Similarly, the large language models (like GPT or Claude) are the next big thing in language technology, and they're set to transform the way we interact with computers.
|
|
@@ -68,6 +70,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
|
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
71
76
|
## 🚀 Get started
|
|
72
77
|
|
|
73
78
|
Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
|
|
@@ -79,6 +84,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
|
|
|
79
84
|
|
|
80
85
|
|
|
81
86
|
|
|
87
|
+
|
|
88
|
+
|
|
82
89
|
## 💜 The Promptbook Project
|
|
83
90
|
|
|
84
91
|
Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
|
|
@@ -114,22 +121,35 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
114
121
|
</tbody>
|
|
115
122
|
</table>
|
|
116
123
|
|
|
124
|
+
Hello world examples:
|
|
125
|
+
|
|
126
|
+
- [Hello world](https://github.com/webgptorg/hello-world)
|
|
127
|
+
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
128
|
+
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
117
132
|
We also have a community of developers and users of **Promptbook**:
|
|
118
133
|
|
|
119
134
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
120
135
|
- [Landing page `ptbk.io`](https://ptbk.io)
|
|
121
136
|
- [Github discussions](https://github.com/webgptorg/promptbook/discussions)
|
|
122
137
|
- [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
|
|
123
|
-
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
138
|
+
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
124
139
|
|
|
125
140
|
And **Promptbook.studio** branded socials:
|
|
126
141
|
|
|
142
|
+
|
|
143
|
+
|
|
127
144
|
- [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
|
|
128
145
|
|
|
129
146
|
And **Promptujeme** sub-brand:
|
|
130
147
|
|
|
131
148
|
_/Subbrand for Czech clients/_
|
|
132
149
|
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
133
153
|
- [Promptujeme.cz](https://www.promptujeme.cz/)
|
|
134
154
|
- [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
|
|
135
155
|
|
|
@@ -147,6 +167,8 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
|
|
|
147
167
|
|
|
148
168
|
## 💙 The Book language
|
|
149
169
|
|
|
170
|
+
|
|
171
|
+
|
|
150
172
|
Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
|
|
151
173
|
|
|
152
174
|
Book is a language that can be used to write AI applications, agents, workflows, automations, knowledgebases, translators, sheet processors, email automations and more. It allows you to harness the power of AI models in human-like terms, without the need to know the specifics and technicalities of the models.
|
|
@@ -196,6 +218,8 @@ Personas can have access to different knowledge, tools and actions. They can als
|
|
|
196
218
|
|
|
197
219
|
- [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
|
|
198
220
|
|
|
221
|
+
|
|
222
|
+
|
|
199
223
|
### **How:** Knowledge, Instruments and Actions
|
|
200
224
|
|
|
201
225
|
The resources used by the personas are used to do the work.
|
|
@@ -271,11 +295,9 @@ Or you can install them separately:
|
|
|
271
295
|
|
|
272
296
|
## 📚 Dictionary
|
|
273
297
|
|
|
274
|
-
### 📚 Dictionary
|
|
275
|
-
|
|
276
298
|
The following glossary is used to clarify certain concepts:
|
|
277
299
|
|
|
278
|
-
|
|
300
|
+
### General LLM / AI terms
|
|
279
301
|
|
|
280
302
|
- **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
|
|
281
303
|
- **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
|
|
@@ -286,9 +308,13 @@ The following glossary is used to clarify certain concepts:
|
|
|
286
308
|
- **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
|
|
287
309
|
- **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
|
|
288
310
|
|
|
289
|
-
_Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
290
311
|
|
|
291
|
-
|
|
312
|
+
|
|
313
|
+
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
### 💯 Core concepts
|
|
292
318
|
|
|
293
319
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
294
320
|
- [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
|
|
@@ -301,7 +327,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
301
327
|
- [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
|
|
302
328
|
- [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
|
|
303
329
|
|
|
304
|
-
|
|
330
|
+
#### Advanced concepts
|
|
305
331
|
|
|
306
332
|
- [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
|
|
307
333
|
- [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
|
|
@@ -316,11 +342,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
|
|
|
316
342
|
- [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
|
|
317
343
|
- [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
|
|
318
344
|
|
|
319
|
-
### Terms specific to Promptbook TypeScript implementation
|
|
320
|
-
|
|
321
|
-
- Anonymous mode
|
|
322
|
-
- Application mode
|
|
323
|
-
|
|
324
345
|
|
|
325
346
|
|
|
326
347
|
## 🚂 Promptbook Engine
|
|
@@ -391,11 +412,11 @@ See [TODO.md](./TODO.md)
|
|
|
391
412
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
392
413
|
|
|
393
414
|
<a href="https://promptbook.studio/">
|
|
394
|
-
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="
|
|
415
|
+
<img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
|
|
395
416
|
</a>
|
|
396
417
|
|
|
397
418
|
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
398
|
-
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="
|
|
419
|
+
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
399
420
|
</a>
|
|
400
421
|
|
|
401
422
|
</div>
|
package/esm/index.es.js
CHANGED
|
@@ -7,8 +7,8 @@ import { mkdir, rm } from 'fs/promises';
|
|
|
7
7
|
import { basename, join, dirname } from 'path';
|
|
8
8
|
import { format } from 'prettier';
|
|
9
9
|
import parserHtml from 'prettier/parser-html';
|
|
10
|
-
import { Subject } from 'rxjs';
|
|
11
10
|
import { randomBytes } from 'crypto';
|
|
11
|
+
import { Subject } from 'rxjs';
|
|
12
12
|
import { forTime } from 'waitasecond';
|
|
13
13
|
import sha256 from 'crypto-js/sha256';
|
|
14
14
|
import { lookup, extension } from 'mime-types';
|
|
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
29
29
|
* @generated
|
|
30
30
|
* @see https://github.com/webgptorg/promptbook
|
|
31
31
|
*/
|
|
32
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
|
|
33
33
|
/**
|
|
34
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
35
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -188,7 +188,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
188
188
|
*
|
|
189
189
|
* @public exported from `@promptbook/core`
|
|
190
190
|
*/
|
|
191
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
191
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
192
192
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
193
193
|
/**
|
|
194
194
|
* Where to store the temporary downloads
|
|
@@ -2154,6 +2154,21 @@ class MissingToolsError extends Error {
|
|
|
2154
2154
|
}
|
|
2155
2155
|
}
|
|
2156
2156
|
|
|
2157
|
+
/**
|
|
2158
|
+
* Generates random token
|
|
2159
|
+
*
|
|
2160
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2161
|
+
*
|
|
2162
|
+
* @private internal helper function
|
|
2163
|
+
* @returns secure random token
|
|
2164
|
+
*/
|
|
2165
|
+
function $randomToken(randomness) {
|
|
2166
|
+
return randomBytes(randomness).toString('hex');
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2170
|
+
*/
|
|
2171
|
+
|
|
2157
2172
|
/**
|
|
2158
2173
|
* This error indicates errors during the execution of the pipeline
|
|
2159
2174
|
*
|
|
@@ -2161,11 +2176,17 @@ class MissingToolsError extends Error {
|
|
|
2161
2176
|
*/
|
|
2162
2177
|
class PipelineExecutionError extends Error {
|
|
2163
2178
|
constructor(message) {
|
|
2179
|
+
// Added id parameter
|
|
2164
2180
|
super(message);
|
|
2165
2181
|
this.name = 'PipelineExecutionError';
|
|
2182
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
2183
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2166
2184
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
2167
2185
|
}
|
|
2168
2186
|
}
|
|
2187
|
+
/**
|
|
2188
|
+
* TODO: !!!!!! Add id to all errors
|
|
2189
|
+
*/
|
|
2169
2190
|
|
|
2170
2191
|
/**
|
|
2171
2192
|
* Determine if the pipeline is fully prepared
|
|
@@ -2204,21 +2225,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
2204
2225
|
* - [♨] Are tasks prepared
|
|
2205
2226
|
*/
|
|
2206
2227
|
|
|
2207
|
-
/**
|
|
2208
|
-
* Generates random token
|
|
2209
|
-
*
|
|
2210
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2211
|
-
*
|
|
2212
|
-
* @private internal helper function
|
|
2213
|
-
* @returns secure random token
|
|
2214
|
-
*/
|
|
2215
|
-
function $randomToken(randomness) {
|
|
2216
|
-
return randomBytes(randomness).toString('hex');
|
|
2217
|
-
}
|
|
2218
|
-
/**
|
|
2219
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2220
|
-
*/
|
|
2221
|
-
|
|
2222
2228
|
/**
|
|
2223
2229
|
* Recursively converts JSON strings to JSON objects
|
|
2224
2230
|
|
|
@@ -2386,7 +2392,7 @@ const ALL_ERRORS = {
|
|
|
2386
2392
|
* @public exported from `@promptbook/utils`
|
|
2387
2393
|
*/
|
|
2388
2394
|
function deserializeError(error) {
|
|
2389
|
-
const { name, stack } = error;
|
|
2395
|
+
const { name, stack, id } = error; // Added id
|
|
2390
2396
|
let { message } = error;
|
|
2391
2397
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2392
2398
|
if (ErrorClass === undefined) {
|
|
@@ -2401,7 +2407,9 @@ function deserializeError(error) {
|
|
|
2401
2407
|
${block(stack || '')}
|
|
2402
2408
|
`);
|
|
2403
2409
|
}
|
|
2404
|
-
|
|
2410
|
+
const deserializedError = new ErrorClass(message);
|
|
2411
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2412
|
+
return deserializedError;
|
|
2405
2413
|
}
|
|
2406
2414
|
|
|
2407
2415
|
/**
|
|
@@ -2451,6 +2459,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2451
2459
|
*/
|
|
2452
2460
|
function createTask(options) {
|
|
2453
2461
|
const { taskType, taskProcessCallback } = options;
|
|
2462
|
+
// TODO: [🐙] DRY
|
|
2454
2463
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2455
2464
|
let status = 'RUNNING';
|
|
2456
2465
|
const createdAt = new Date();
|
|
@@ -2483,7 +2492,7 @@ function createTask(options) {
|
|
|
2483
2492
|
assertsTaskSuccessful(executionResult);
|
|
2484
2493
|
status = 'FINISHED';
|
|
2485
2494
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2486
|
-
// <- TODO:
|
|
2495
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2487
2496
|
partialResultSubject.next(executionResult);
|
|
2488
2497
|
}
|
|
2489
2498
|
catch (error) {
|
|
@@ -2547,19 +2556,21 @@ function createTask(options) {
|
|
|
2547
2556
|
*/
|
|
2548
2557
|
function serializeError(error) {
|
|
2549
2558
|
const { name, message, stack } = error;
|
|
2559
|
+
const { id } = error;
|
|
2550
2560
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2551
2561
|
console.error(spaceTrim$1((block) => `
|
|
2552
|
-
|
|
2562
|
+
|
|
2553
2563
|
Cannot serialize error with name "${name}"
|
|
2554
2564
|
|
|
2555
2565
|
${block(stack || message)}
|
|
2556
|
-
|
|
2566
|
+
|
|
2557
2567
|
`));
|
|
2558
2568
|
}
|
|
2559
2569
|
return {
|
|
2560
2570
|
name: name,
|
|
2561
2571
|
message,
|
|
2562
2572
|
stack,
|
|
2573
|
+
id, // Include id in the serialized object
|
|
2563
2574
|
};
|
|
2564
2575
|
}
|
|
2565
2576
|
|
|
@@ -2702,8 +2713,9 @@ function addUsage(...usageItems) {
|
|
|
2702
2713
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2703
2714
|
* @public exported from `@promptbook/core`
|
|
2704
2715
|
*/
|
|
2705
|
-
function
|
|
2716
|
+
function countUsage(llmTools) {
|
|
2706
2717
|
let totalUsage = ZERO_USAGE;
|
|
2718
|
+
const spending = new Subject();
|
|
2707
2719
|
const proxyTools = {
|
|
2708
2720
|
get title() {
|
|
2709
2721
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2713,12 +2725,15 @@ function countTotalUsage(llmTools) {
|
|
|
2713
2725
|
// TODO: [🧠] Maybe put here some suffix
|
|
2714
2726
|
return llmTools.description;
|
|
2715
2727
|
},
|
|
2716
|
-
|
|
2728
|
+
checkConfiguration() {
|
|
2717
2729
|
return /* not await */ llmTools.checkConfiguration();
|
|
2718
2730
|
},
|
|
2719
2731
|
listModels() {
|
|
2720
2732
|
return /* not await */ llmTools.listModels();
|
|
2721
2733
|
},
|
|
2734
|
+
spending() {
|
|
2735
|
+
return spending.asObservable();
|
|
2736
|
+
},
|
|
2722
2737
|
getTotalUsage() {
|
|
2723
2738
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2724
2739
|
return totalUsage;
|
|
@@ -2729,6 +2744,7 @@ function countTotalUsage(llmTools) {
|
|
|
2729
2744
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2730
2745
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2731
2746
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2747
|
+
spending.next(promptResult.usage);
|
|
2732
2748
|
return promptResult;
|
|
2733
2749
|
};
|
|
2734
2750
|
}
|
|
@@ -2737,6 +2753,7 @@ function countTotalUsage(llmTools) {
|
|
|
2737
2753
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2738
2754
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2739
2755
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2756
|
+
spending.next(promptResult.usage);
|
|
2740
2757
|
return promptResult;
|
|
2741
2758
|
};
|
|
2742
2759
|
}
|
|
@@ -2745,6 +2762,7 @@ function countTotalUsage(llmTools) {
|
|
|
2745
2762
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2746
2763
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2747
2764
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2765
|
+
spending.next(promptResult.usage);
|
|
2748
2766
|
return promptResult;
|
|
2749
2767
|
};
|
|
2750
2768
|
}
|
|
@@ -3527,7 +3545,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3527
3545
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3528
3546
|
const _llms = arrayableToArray(tools.llm);
|
|
3529
3547
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3530
|
-
const llmToolsWithUsage =
|
|
3548
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3531
3549
|
// <- TODO: [🌯]
|
|
3532
3550
|
/*
|
|
3533
3551
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -4357,6 +4375,9 @@ function countCharacters(text) {
|
|
|
4357
4375
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4358
4376
|
return text.length;
|
|
4359
4377
|
}
|
|
4378
|
+
/**
|
|
4379
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4380
|
+
*/
|
|
4360
4381
|
|
|
4361
4382
|
/**
|
|
4362
4383
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4388,6 +4409,9 @@ function countLines(text) {
|
|
|
4388
4409
|
const lines = text.split('\n');
|
|
4389
4410
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4390
4411
|
}
|
|
4412
|
+
/**
|
|
4413
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4414
|
+
*/
|
|
4391
4415
|
|
|
4392
4416
|
/**
|
|
4393
4417
|
* Counts number of pages in the text
|
|
@@ -4399,6 +4423,9 @@ function countLines(text) {
|
|
|
4399
4423
|
function countPages(text) {
|
|
4400
4424
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4401
4425
|
}
|
|
4426
|
+
/**
|
|
4427
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4428
|
+
*/
|
|
4402
4429
|
|
|
4403
4430
|
/**
|
|
4404
4431
|
* Counts number of paragraphs in the text
|
|
@@ -4408,6 +4435,9 @@ function countPages(text) {
|
|
|
4408
4435
|
function countParagraphs(text) {
|
|
4409
4436
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4410
4437
|
}
|
|
4438
|
+
/**
|
|
4439
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4440
|
+
*/
|
|
4411
4441
|
|
|
4412
4442
|
/**
|
|
4413
4443
|
* Split text into sentences
|
|
@@ -4425,6 +4455,9 @@ function splitIntoSentences(text) {
|
|
|
4425
4455
|
function countSentences(text) {
|
|
4426
4456
|
return splitIntoSentences(text).length;
|
|
4427
4457
|
}
|
|
4458
|
+
/**
|
|
4459
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4460
|
+
*/
|
|
4428
4461
|
|
|
4429
4462
|
/**
|
|
4430
4463
|
* Counts number of words in the text
|
|
@@ -4438,6 +4471,9 @@ function countWords(text) {
|
|
|
4438
4471
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4439
4472
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4440
4473
|
}
|
|
4474
|
+
/**
|
|
4475
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4476
|
+
*/
|
|
4441
4477
|
|
|
4442
4478
|
/**
|
|
4443
4479
|
* Index of all counter functions
|