Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@promptbook/utils

Package Overview
Dependencies
Maintainers
1
Versions
470
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@promptbook/utils - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

71

esm/index.es.js

@@ -56,2 +56,19 @@ import spaceTrim from 'spacetrim';

function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
/**

@@ -160,22 +177,51 @@ * All possible emoji chars like "๐Ÿ†", "๐Ÿก", "๐Ÿค"...

*/
function unwrapResult(text) {
function unwrapResult(text, options) {
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c;
var originalText = text;
// Remove leading and trailing spaces and newlines
text = spaceTrim(text);
// Check if the text starts with a sentence followed by quotes
var introduceSentenceRegex = /^[^"'\n]*/;
if (introduceSentenceRegex.test(text)) {
// Remove the introduce sentence and quotes by replacing it with an empty string
text = text.replace(introduceSentenceRegex, '');
if (isTrimmed) {
text = spaceTrim(text);
}
text = spaceTrim(text);
if (isIntroduceSentenceRemoved) {
var introduceSentenceRegex = /^[a-zฤ›ลกฤล™ลพรฝรกรญรฉรบลฏ:\s]*/i;
if (introduceSentenceRegex.test(text)) {
// Remove the introduce sentence and quotes by replacing it with an empty string
text = text.replace(introduceSentenceRegex, '');
}
text = spaceTrim(text);
}
if (text.length < 3) {
return originalText;
}
if (text.includes('\n')) {
return originalText;
}
// Remove the quotes by extracting the substring without the first and last characters
var unquotedText = text.slice(1, -1);
// Check if the text starts and ends with quotes
if ((text.startsWith('\'') && !unquotedText.includes('\'') && text.endsWith('\'')) ||
(text.startsWith('"') && !unquotedText.includes('"') && text.endsWith('"'))) {
return unquotedText;
if ([
['"', '"'],
["'", "'"],
['`', '`'],
['*', '*'],
['_', '_'],
['โ€ž', 'โ€œ'],
['ยซ', 'ยป'] /* <- QUOTES to config */,
].some(function (_a) {
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
if (!text.startsWith(startQuote)) {
return false;
}
if (!text.endsWith(endQuote)) {
return false;
}
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
return false;
}
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
return false;
}
return true;
})) {
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
}

@@ -186,4 +232,7 @@ else {

}
/**
* TODO: [๐Ÿง ] Should this also unwrap the (parenthesis)
*/
export { removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, unwrapResult };
//# sourceMappingURL=index.es.js.map

2

esm/typings/types/TaskProgress.d.ts

@@ -18,3 +18,3 @@ import { ExecutionType } from './ExecutionTypes';

* Note: This is supposed to be displayed to the user.
* Note: This is trimmed and stripped of HTML tags and emojis with "๐Ÿ–‹" prefix
* Note: This is trimmed and stripped of HTML tags and emojis
*/

@@ -21,0 +21,0 @@ readonly title: string_title;

/**
* Additional options for `unwrapResult`
*/
interface UnwrapResultOptions {
/**
* If true, the text is trimmed before processing
*/
isTrimmed?: boolean;
/**
* If true, the introduce sentence is removed
*
* For example:
* - If `true`> 'Hello, "world"' -> 'world'
* - If `false`> 'Hello, "world"' -> 'Hello, "world"'
*
* @default true
*/
isIntroduceSentenceRemoved?: boolean;
}
/**
* Removes quotes and optional introduce text from a string

@@ -13,2 +32,6 @@ *

*/
export declare function unwrapResult(text: string): string;
export declare function unwrapResult(text: string, options?: UnwrapResultOptions): string;
export {};
/**
* TODO: [๐Ÿง ] Should this also unwrap the (parenthesis)
*/
{
"name": "@promptbook/utils",
"version": "0.15.0",
"version": "0.16.0",
"description": "Library to supercharge your use of large language models",

@@ -40,3 +40,3 @@ "private": false,

"peerDependencies": {
"@promptbook/core": "0.15.0"
"@promptbook/core": "0.16.0"
},

@@ -43,0 +43,0 @@ "main": "./umd/index.umd.js",

@@ -64,2 +64,19 @@ (function (global, factory) {

function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
/**

@@ -168,22 +185,51 @@ * All possible emoji chars like "๐Ÿ†", "๐Ÿก", "๐Ÿค"...

*/
function unwrapResult(text) {
function unwrapResult(text, options) {
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c;
var originalText = text;
// Remove leading and trailing spaces and newlines
text = spaceTrim__default["default"](text);
// Check if the text starts with a sentence followed by quotes
var introduceSentenceRegex = /^[^"'\n]*/;
if (introduceSentenceRegex.test(text)) {
// Remove the introduce sentence and quotes by replacing it with an empty string
text = text.replace(introduceSentenceRegex, '');
if (isTrimmed) {
text = spaceTrim__default["default"](text);
}
text = spaceTrim__default["default"](text);
if (isIntroduceSentenceRemoved) {
var introduceSentenceRegex = /^[a-zฤ›ลกฤล™ลพรฝรกรญรฉรบลฏ:\s]*/i;
if (introduceSentenceRegex.test(text)) {
// Remove the introduce sentence and quotes by replacing it with an empty string
text = text.replace(introduceSentenceRegex, '');
}
text = spaceTrim__default["default"](text);
}
if (text.length < 3) {
return originalText;
}
if (text.includes('\n')) {
return originalText;
}
// Remove the quotes by extracting the substring without the first and last characters
var unquotedText = text.slice(1, -1);
// Check if the text starts and ends with quotes
if ((text.startsWith('\'') && !unquotedText.includes('\'') && text.endsWith('\'')) ||
(text.startsWith('"') && !unquotedText.includes('"') && text.endsWith('"'))) {
return unquotedText;
if ([
['"', '"'],
["'", "'"],
['`', '`'],
['*', '*'],
['_', '_'],
['โ€ž', 'โ€œ'],
['ยซ', 'ยป'] /* <- QUOTES to config */,
].some(function (_a) {
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
if (!text.startsWith(startQuote)) {
return false;
}
if (!text.endsWith(endQuote)) {
return false;
}
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
return false;
}
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
return false;
}
return true;
})) {
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
}

@@ -194,2 +240,5 @@ else {

}
/**
* TODO: [๐Ÿง ] Should this also unwrap the (parenthesis)
*/

@@ -196,0 +245,0 @@ exports.removeContentComments = removeContentComments;

@@ -18,3 +18,3 @@ import { ExecutionType } from './ExecutionTypes';

* Note: This is supposed to be displayed to the user.
* Note: This is trimmed and stripped of HTML tags and emojis with "๐Ÿ–‹" prefix
* Note: This is trimmed and stripped of HTML tags and emojis
*/

@@ -21,0 +21,0 @@ readonly title: string_title;

/**
* Additional options for `unwrapResult`
*/
interface UnwrapResultOptions {
/**
* If true, the text is trimmed before processing
*/
isTrimmed?: boolean;
/**
* If true, the introduce sentence is removed
*
* For example:
* - If `true`> 'Hello, "world"' -> 'world'
* - If `false`> 'Hello, "world"' -> 'Hello, "world"'
*
* @default true
*/
isIntroduceSentenceRemoved?: boolean;
}
/**
* Removes quotes and optional introduce text from a string

@@ -13,2 +32,6 @@ *

*/
export declare function unwrapResult(text: string): string;
export declare function unwrapResult(text: string, options?: UnwrapResultOptions): string;
export {};
/**
* TODO: [๐Ÿง ] Should this also unwrap the (parenthesis)
*/

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc