@promptbook/markdown-utils 0.89.0-30 → 0.89.0-32
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/esm/index.es.js +52 -3
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +52 -3
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-32';
|
|
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
|
|
@@ -465,6 +465,9 @@ function assertsError(whatWasThrown) {
|
|
|
465
465
|
/**
|
|
466
466
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
467
467
|
*
|
|
468
|
+
* @param value The string to check
|
|
469
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
470
|
+
*
|
|
468
471
|
* @public exported from `@promptbook/utils`
|
|
469
472
|
*/
|
|
470
473
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -4096,6 +4099,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
4096
4099
|
// encoding: 'utf-8',
|
|
4097
4100
|
});
|
|
4098
4101
|
|
|
4102
|
+
/**
|
|
4103
|
+
* Function to check if a string is valid CSV
|
|
4104
|
+
*
|
|
4105
|
+
* @param value The string to check
|
|
4106
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
4107
|
+
*
|
|
4108
|
+
* @public exported from `@promptbook/utils`
|
|
4109
|
+
*/
|
|
4110
|
+
function isValidCsvString(value) {
|
|
4111
|
+
try {
|
|
4112
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
4113
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
4114
|
+
return true;
|
|
4115
|
+
}
|
|
4116
|
+
return false;
|
|
4117
|
+
}
|
|
4118
|
+
catch (error) {
|
|
4119
|
+
assertsError(error);
|
|
4120
|
+
return false;
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4099
4124
|
/**
|
|
4100
4125
|
* Definition for CSV spreadsheet
|
|
4101
4126
|
*
|
|
@@ -4106,7 +4131,7 @@ const CsvFormatDefinition = {
|
|
|
4106
4131
|
formatName: 'CSV',
|
|
4107
4132
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4108
4133
|
isValid(value, settings, schema) {
|
|
4109
|
-
return
|
|
4134
|
+
return isValidCsvString(value);
|
|
4110
4135
|
},
|
|
4111
4136
|
canBeValid(partialValue, settings, schema) {
|
|
4112
4137
|
return true;
|
|
@@ -4260,6 +4285,30 @@ const TextFormatDefinition = {
|
|
|
4260
4285
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4261
4286
|
*/
|
|
4262
4287
|
|
|
4288
|
+
/**
|
|
4289
|
+
* Function to check if a string is valid XML
|
|
4290
|
+
*
|
|
4291
|
+
* @param value
|
|
4292
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
4293
|
+
*
|
|
4294
|
+
* @public exported from `@promptbook/utils`
|
|
4295
|
+
*/
|
|
4296
|
+
function isValidXmlString(value) {
|
|
4297
|
+
try {
|
|
4298
|
+
const parser = new DOMParser();
|
|
4299
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
4300
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
4301
|
+
if (parserError.length > 0) {
|
|
4302
|
+
return false;
|
|
4303
|
+
}
|
|
4304
|
+
return true;
|
|
4305
|
+
}
|
|
4306
|
+
catch (error) {
|
|
4307
|
+
assertsError(error);
|
|
4308
|
+
return false;
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
|
|
4263
4312
|
/**
|
|
4264
4313
|
* Definition for XML format
|
|
4265
4314
|
*
|
|
@@ -4269,7 +4318,7 @@ const XmlFormatDefinition = {
|
|
|
4269
4318
|
formatName: 'XML',
|
|
4270
4319
|
mimeType: 'application/xml',
|
|
4271
4320
|
isValid(value, settings, schema) {
|
|
4272
|
-
return
|
|
4321
|
+
return isValidXmlString(value);
|
|
4273
4322
|
},
|
|
4274
4323
|
canBeValid(partialValue, settings, schema) {
|
|
4275
4324
|
return true;
|