@promptbook/pdf 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/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ export type PromptbookServer_AnonymousIdentification = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Identifier of the end user
|
|
39
39
|
*
|
|
40
|
-
* Note:
|
|
40
|
+
* Note: This can be either some id or email or any other identifier
|
|
41
|
+
* Note: In anonymous mode, this is passed to the certain model providers to identify misuse
|
|
41
42
|
* Note: In anonymous mode, there is no need to identify yourself, nor does it change the actual configuration of LLM Tools (unlike in application mode)
|
|
42
43
|
*/
|
|
43
44
|
readonly userId?: string_user_id;
|
|
@@ -58,15 +58,27 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
|
|
|
58
58
|
};
|
|
59
59
|
export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Identifier of the application
|
|
62
|
+
*
|
|
63
|
+
* Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
|
|
64
|
+
* Note: This can be some id or some semantic name like "email-agent"
|
|
62
65
|
*/
|
|
63
66
|
readonly appId: string_app_id | null;
|
|
64
67
|
/**
|
|
65
|
-
*
|
|
68
|
+
* Identifier of the end user
|
|
69
|
+
*
|
|
70
|
+
* Note: This can be either some id or email or any other identifier
|
|
71
|
+
* Note: This is also passed to the certain model providers to identify misuse
|
|
66
72
|
*/
|
|
67
73
|
readonly userId?: string_user_id;
|
|
68
74
|
/**
|
|
69
|
-
*
|
|
75
|
+
* Token of the user to verify its identity
|
|
76
|
+
*
|
|
77
|
+
* Note: This is passed for example to `createLlmExecutionTools`
|
|
78
|
+
*/
|
|
79
|
+
readonly userToken?: string_user_id;
|
|
80
|
+
/**
|
|
81
|
+
* Additional arbitrary options to identify the client or to pass custom metadata
|
|
70
82
|
*/
|
|
71
83
|
readonly customOptions?: TCustomOptions;
|
|
72
84
|
};
|
|
@@ -433,13 +433,13 @@ export type string_uuid = string & {
|
|
|
433
433
|
*
|
|
434
434
|
* @@@
|
|
435
435
|
*/
|
|
436
|
-
export type string_app_id = id;
|
|
436
|
+
export type string_app_id = id | 'app';
|
|
437
437
|
/**
|
|
438
438
|
* End user identifier
|
|
439
439
|
*
|
|
440
440
|
* @@@
|
|
441
441
|
*/
|
|
442
|
-
export type string_user_id = id;
|
|
442
|
+
export type string_user_id = id | string_email;
|
|
443
443
|
/**
|
|
444
444
|
* Semantic helper
|
|
445
445
|
*
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countCharacters(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countLines(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countPages(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countParagraphs(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -11,3 +11,6 @@ export declare function splitIntoSentences(text: string): ReadonlyArray<string>;
|
|
|
11
11
|
* @public exported from `@promptbook/utils`
|
|
12
12
|
*/
|
|
13
13
|
export declare function countSentences(text: string): ExpectationAmount;
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
16
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countWords(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0-1",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/pdf.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.
|
|
50
|
+
"@promptbook/core": "0.89.0-1"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"crypto": "^1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, crypto, rxjs, waitasecond, sha256, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
*
|
|
158
158
|
* @public exported from `@promptbook/core`
|
|
159
159
|
*/
|
|
160
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
160
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
161
161
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
162
162
|
/**
|
|
163
163
|
* Where to store the temporary downloads
|
|
@@ -2015,6 +2015,21 @@
|
|
|
2015
2015
|
}
|
|
2016
2016
|
}
|
|
2017
2017
|
|
|
2018
|
+
/**
|
|
2019
|
+
* Generates random token
|
|
2020
|
+
*
|
|
2021
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2022
|
+
*
|
|
2023
|
+
* @private internal helper function
|
|
2024
|
+
* @returns secure random token
|
|
2025
|
+
*/
|
|
2026
|
+
function $randomToken(randomness) {
|
|
2027
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2031
|
+
*/
|
|
2032
|
+
|
|
2018
2033
|
/**
|
|
2019
2034
|
* This error indicates errors during the execution of the pipeline
|
|
2020
2035
|
*
|
|
@@ -2022,11 +2037,17 @@
|
|
|
2022
2037
|
*/
|
|
2023
2038
|
class PipelineExecutionError extends Error {
|
|
2024
2039
|
constructor(message) {
|
|
2040
|
+
// Added id parameter
|
|
2025
2041
|
super(message);
|
|
2026
2042
|
this.name = 'PipelineExecutionError';
|
|
2043
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
2044
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2027
2045
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
2028
2046
|
}
|
|
2029
2047
|
}
|
|
2048
|
+
/**
|
|
2049
|
+
* TODO: !!!!!! Add id to all errors
|
|
2050
|
+
*/
|
|
2030
2051
|
|
|
2031
2052
|
/**
|
|
2032
2053
|
* Determine if the pipeline is fully prepared
|
|
@@ -2065,21 +2086,6 @@
|
|
|
2065
2086
|
* - [♨] Are tasks prepared
|
|
2066
2087
|
*/
|
|
2067
2088
|
|
|
2068
|
-
/**
|
|
2069
|
-
* Generates random token
|
|
2070
|
-
*
|
|
2071
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2072
|
-
*
|
|
2073
|
-
* @private internal helper function
|
|
2074
|
-
* @returns secure random token
|
|
2075
|
-
*/
|
|
2076
|
-
function $randomToken(randomness) {
|
|
2077
|
-
return crypto.randomBytes(randomness).toString('hex');
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2081
|
-
*/
|
|
2082
|
-
|
|
2083
2089
|
/**
|
|
2084
2090
|
* Recursively converts JSON strings to JSON objects
|
|
2085
2091
|
|
|
@@ -2270,7 +2276,7 @@
|
|
|
2270
2276
|
* @public exported from `@promptbook/utils`
|
|
2271
2277
|
*/
|
|
2272
2278
|
function deserializeError(error) {
|
|
2273
|
-
const { name, stack } = error;
|
|
2279
|
+
const { name, stack, id } = error; // Added id
|
|
2274
2280
|
let { message } = error;
|
|
2275
2281
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2276
2282
|
if (ErrorClass === undefined) {
|
|
@@ -2285,7 +2291,9 @@
|
|
|
2285
2291
|
${block(stack || '')}
|
|
2286
2292
|
`);
|
|
2287
2293
|
}
|
|
2288
|
-
|
|
2294
|
+
const deserializedError = new ErrorClass(message);
|
|
2295
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2296
|
+
return deserializedError;
|
|
2289
2297
|
}
|
|
2290
2298
|
|
|
2291
2299
|
/**
|
|
@@ -2335,6 +2343,7 @@
|
|
|
2335
2343
|
*/
|
|
2336
2344
|
function createTask(options) {
|
|
2337
2345
|
const { taskType, taskProcessCallback } = options;
|
|
2346
|
+
// TODO: [🐙] DRY
|
|
2338
2347
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2339
2348
|
let status = 'RUNNING';
|
|
2340
2349
|
const createdAt = new Date();
|
|
@@ -2367,7 +2376,7 @@
|
|
|
2367
2376
|
assertsTaskSuccessful(executionResult);
|
|
2368
2377
|
status = 'FINISHED';
|
|
2369
2378
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2370
|
-
// <- TODO:
|
|
2379
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2371
2380
|
partialResultSubject.next(executionResult);
|
|
2372
2381
|
}
|
|
2373
2382
|
catch (error) {
|
|
@@ -2431,19 +2440,21 @@
|
|
|
2431
2440
|
*/
|
|
2432
2441
|
function serializeError(error) {
|
|
2433
2442
|
const { name, message, stack } = error;
|
|
2443
|
+
const { id } = error;
|
|
2434
2444
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2435
2445
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2436
|
-
|
|
2446
|
+
|
|
2437
2447
|
Cannot serialize error with name "${name}"
|
|
2438
2448
|
|
|
2439
2449
|
${block(stack || message)}
|
|
2440
|
-
|
|
2450
|
+
|
|
2441
2451
|
`));
|
|
2442
2452
|
}
|
|
2443
2453
|
return {
|
|
2444
2454
|
name: name,
|
|
2445
2455
|
message,
|
|
2446
2456
|
stack,
|
|
2457
|
+
id, // Include id in the serialized object
|
|
2447
2458
|
};
|
|
2448
2459
|
}
|
|
2449
2460
|
|
|
@@ -2586,8 +2597,9 @@
|
|
|
2586
2597
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2587
2598
|
* @public exported from `@promptbook/core`
|
|
2588
2599
|
*/
|
|
2589
|
-
function
|
|
2600
|
+
function countUsage(llmTools) {
|
|
2590
2601
|
let totalUsage = ZERO_USAGE;
|
|
2602
|
+
const spending = new rxjs.Subject();
|
|
2591
2603
|
const proxyTools = {
|
|
2592
2604
|
get title() {
|
|
2593
2605
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2597,12 +2609,15 @@
|
|
|
2597
2609
|
// TODO: [🧠] Maybe put here some suffix
|
|
2598
2610
|
return llmTools.description;
|
|
2599
2611
|
},
|
|
2600
|
-
|
|
2612
|
+
checkConfiguration() {
|
|
2601
2613
|
return /* not await */ llmTools.checkConfiguration();
|
|
2602
2614
|
},
|
|
2603
2615
|
listModels() {
|
|
2604
2616
|
return /* not await */ llmTools.listModels();
|
|
2605
2617
|
},
|
|
2618
|
+
spending() {
|
|
2619
|
+
return spending.asObservable();
|
|
2620
|
+
},
|
|
2606
2621
|
getTotalUsage() {
|
|
2607
2622
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2608
2623
|
return totalUsage;
|
|
@@ -2613,6 +2628,7 @@
|
|
|
2613
2628
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2614
2629
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2615
2630
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2631
|
+
spending.next(promptResult.usage);
|
|
2616
2632
|
return promptResult;
|
|
2617
2633
|
};
|
|
2618
2634
|
}
|
|
@@ -2621,6 +2637,7 @@
|
|
|
2621
2637
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2622
2638
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2623
2639
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2640
|
+
spending.next(promptResult.usage);
|
|
2624
2641
|
return promptResult;
|
|
2625
2642
|
};
|
|
2626
2643
|
}
|
|
@@ -2629,6 +2646,7 @@
|
|
|
2629
2646
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2630
2647
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2631
2648
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2649
|
+
spending.next(promptResult.usage);
|
|
2632
2650
|
return promptResult;
|
|
2633
2651
|
};
|
|
2634
2652
|
}
|
|
@@ -3525,7 +3543,7 @@
|
|
|
3525
3543
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3526
3544
|
const _llms = arrayableToArray(tools.llm);
|
|
3527
3545
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3528
|
-
const llmToolsWithUsage =
|
|
3546
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3529
3547
|
// <- TODO: [🌯]
|
|
3530
3548
|
/*
|
|
3531
3549
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -4355,6 +4373,9 @@
|
|
|
4355
4373
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4356
4374
|
return text.length;
|
|
4357
4375
|
}
|
|
4376
|
+
/**
|
|
4377
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4378
|
+
*/
|
|
4358
4379
|
|
|
4359
4380
|
/**
|
|
4360
4381
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4386,6 +4407,9 @@
|
|
|
4386
4407
|
const lines = text.split('\n');
|
|
4387
4408
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4388
4409
|
}
|
|
4410
|
+
/**
|
|
4411
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4412
|
+
*/
|
|
4389
4413
|
|
|
4390
4414
|
/**
|
|
4391
4415
|
* Counts number of pages in the text
|
|
@@ -4397,6 +4421,9 @@
|
|
|
4397
4421
|
function countPages(text) {
|
|
4398
4422
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4399
4423
|
}
|
|
4424
|
+
/**
|
|
4425
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4426
|
+
*/
|
|
4400
4427
|
|
|
4401
4428
|
/**
|
|
4402
4429
|
* Counts number of paragraphs in the text
|
|
@@ -4406,6 +4433,9 @@
|
|
|
4406
4433
|
function countParagraphs(text) {
|
|
4407
4434
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4408
4435
|
}
|
|
4436
|
+
/**
|
|
4437
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4438
|
+
*/
|
|
4409
4439
|
|
|
4410
4440
|
/**
|
|
4411
4441
|
* Split text into sentences
|
|
@@ -4423,6 +4453,9 @@
|
|
|
4423
4453
|
function countSentences(text) {
|
|
4424
4454
|
return splitIntoSentences(text).length;
|
|
4425
4455
|
}
|
|
4456
|
+
/**
|
|
4457
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4458
|
+
*/
|
|
4426
4459
|
|
|
4427
4460
|
/**
|
|
4428
4461
|
* Counts number of words in the text
|
|
@@ -4436,6 +4469,9 @@
|
|
|
4436
4469
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4437
4470
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4438
4471
|
}
|
|
4472
|
+
/**
|
|
4473
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4474
|
+
*/
|
|
4439
4475
|
|
|
4440
4476
|
/**
|
|
4441
4477
|
* Index of all counter functions
|