@promptbook/utils
Advanced tools
Comparing version 0.17.0 to 0.18.0
@@ -335,23 +335,24 @@ import spaceTrim from 'spacetrim'; | ||
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c; | ||
var originalText = text; | ||
var trimmedText = text; | ||
// Remove leading and trailing spaces and newlines | ||
if (isTrimmed) { | ||
text = spaceTrim(text); | ||
trimmedText = spaceTrim(trimmedText); | ||
} | ||
var processedText = trimmedText; | ||
if (isIntroduceSentenceRemoved) { | ||
var introduceSentenceRegex = /^[a-zฤลกฤลลพรฝรกรญรฉรบลฏ:\s]*/i; | ||
var introduceSentenceRegex = /^[a-zฤลกฤลลพรฝรกรญรฉรบลฏ:\s]*:\s*/i; | ||
if (introduceSentenceRegex.test(text)) { | ||
// Remove the introduce sentence and quotes by replacing it with an empty string | ||
text = text.replace(introduceSentenceRegex, ''); | ||
processedText = processedText.replace(introduceSentenceRegex, ''); | ||
} | ||
text = spaceTrim(text); | ||
processedText = spaceTrim(processedText); | ||
} | ||
if (text.length < 3) { | ||
return originalText; | ||
if (processedText.length < 3) { | ||
return trimmedText; | ||
} | ||
if (text.includes('\n')) { | ||
return originalText; | ||
if (processedText.includes('\n')) { | ||
return trimmedText; | ||
} | ||
// Remove the quotes by extracting the substring without the first and last characters | ||
var unquotedText = text.slice(1, -1); | ||
var unquotedText = processedText.slice(1, -1); | ||
// Check if the text starts and ends with quotes | ||
@@ -368,6 +369,6 @@ if ([ | ||
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1]; | ||
if (!text.startsWith(startQuote)) { | ||
if (!processedText.startsWith(startQuote)) { | ||
return false; | ||
} | ||
if (!text.endsWith(endQuote)) { | ||
if (!processedText.endsWith(endQuote)) { | ||
return false; | ||
@@ -386,3 +387,3 @@ } | ||
else { | ||
return originalText; | ||
return processedText; | ||
} | ||
@@ -389,0 +390,0 @@ } |
{ | ||
"name": "@promptbook/utils", | ||
"version": "0.17.0", | ||
"version": "0.18.0", | ||
"description": "Library to supercharge your use of large language models", | ||
@@ -40,3 +40,3 @@ "private": false, | ||
"peerDependencies": { | ||
"@promptbook/core": "0.17.0" | ||
"@promptbook/core": "0.18.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "main": "./umd/index.umd.js", |
@@ -343,23 +343,24 @@ (function (global, factory) { | ||
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c; | ||
var originalText = text; | ||
var trimmedText = text; | ||
// Remove leading and trailing spaces and newlines | ||
if (isTrimmed) { | ||
text = spaceTrim__default["default"](text); | ||
trimmedText = spaceTrim__default["default"](trimmedText); | ||
} | ||
var processedText = trimmedText; | ||
if (isIntroduceSentenceRemoved) { | ||
var introduceSentenceRegex = /^[a-zฤลกฤลลพรฝรกรญรฉรบลฏ:\s]*/i; | ||
var introduceSentenceRegex = /^[a-zฤลกฤลลพรฝรกรญรฉรบลฏ:\s]*:\s*/i; | ||
if (introduceSentenceRegex.test(text)) { | ||
// Remove the introduce sentence and quotes by replacing it with an empty string | ||
text = text.replace(introduceSentenceRegex, ''); | ||
processedText = processedText.replace(introduceSentenceRegex, ''); | ||
} | ||
text = spaceTrim__default["default"](text); | ||
processedText = spaceTrim__default["default"](processedText); | ||
} | ||
if (text.length < 3) { | ||
return originalText; | ||
if (processedText.length < 3) { | ||
return trimmedText; | ||
} | ||
if (text.includes('\n')) { | ||
return originalText; | ||
if (processedText.includes('\n')) { | ||
return trimmedText; | ||
} | ||
// Remove the quotes by extracting the substring without the first and last characters | ||
var unquotedText = text.slice(1, -1); | ||
var unquotedText = processedText.slice(1, -1); | ||
// Check if the text starts and ends with quotes | ||
@@ -376,6 +377,6 @@ if ([ | ||
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1]; | ||
if (!text.startsWith(startQuote)) { | ||
if (!processedText.startsWith(startQuote)) { | ||
return false; | ||
} | ||
if (!text.endsWith(endQuote)) { | ||
if (!processedText.endsWith(endQuote)) { | ||
return false; | ||
@@ -394,3 +395,3 @@ } | ||
else { | ||
return originalText; | ||
return processedText; | ||
} | ||
@@ -397,0 +398,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
400308
5174