@adobe/spacecat-shared-utils 1.26.6 → 1.27.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/helpers.js +18 -0
- package/src/index.d.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.27.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.6...@adobe/spacecat-shared-utils-v1.27.0) (2025-01-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* introduce replace placeholders for prompts ([#551](https://github.com/adobe/spacecat-shared/issues/551)) ([d3b542c](https://github.com/adobe/spacecat-shared/commit/d3b542cf1b546256b3108f989220d07410cdc87d))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-utils-v1.26.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.5...@adobe/spacecat-shared-utils-v1.26.6) (2025-01-18)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/helpers.js
CHANGED
|
@@ -92,3 +92,21 @@ export function generateCSVFile(data) {
|
|
|
92
92
|
const json2csvParser = new Parser();
|
|
93
93
|
return Buffer.from(json2csvParser.parse(data), 'utf-8');
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Replaces placeholders in the prompt content with their corresponding values.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} content - The prompt content with placeholders.
|
|
100
|
+
* @param {Object} placeholders - The placeholders and their values.
|
|
101
|
+
* @returns {string} - The content with placeholders replaced.
|
|
102
|
+
*/
|
|
103
|
+
export function replacePlaceholders(content, placeholders) {
|
|
104
|
+
return content.replace(/{{(.*?)}}/g, (match, key) => {
|
|
105
|
+
if (key in placeholders) {
|
|
106
|
+
const value = placeholders[key];
|
|
107
|
+
return typeof value === 'object' && value !== null ? JSON.stringify(value) : value;
|
|
108
|
+
} else {
|
|
109
|
+
return match;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -143,6 +143,15 @@ declare function getRUMDomainKey(baseURL: string, ctx: object): Promise<string>;
|
|
|
143
143
|
*/
|
|
144
144
|
declare function generateCSVFile(data: object[]): Buffer;
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Replaces placeholders in the prompt content with their corresponding values.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} content - The prompt content with placeholders.
|
|
150
|
+
* @param {Object} placeholders - The placeholders and their values.
|
|
151
|
+
* @returns {string} - The content with placeholders replaced.
|
|
152
|
+
*/
|
|
153
|
+
declare function replacePlaceholders(content: string, placeholders: object): string;
|
|
154
|
+
|
|
146
155
|
/**
|
|
147
156
|
* Retrieves stored metrics from S3.
|
|
148
157
|
* @param config - Configuration object
|