ai-replace-prompt 1770195.248.27

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.
Files changed (4) hide show
  1. package/README.md +88 -0
  2. package/example.js +83 -0
  3. package/index.js +90 -0
  4. package/package.json +18 -0
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # ai-replace-prompt
2
+
3
+ A lightweight JavaScript library for generating optimized AI replacement prompts based on user input. This utility helps streamline the creation of effective prompts for image editing and transformation tasks.
4
+
5
+ ## Installation
6
+ bash
7
+ npm install ai-replace-prompt
8
+
9
+ ## Usage Examples
10
+
11
+ Here are several examples demonstrating how to use `ai-replace-prompt` in your JavaScript or Node.js projects:
12
+
13
+ **Example 1: Basic Replacement**
14
+ javascript
15
+ const { generatePrompt } = require('ai-replace-prompt');
16
+
17
+ const targetObject = "the sky";
18
+ const replacementObject = "a starry night";
19
+
20
+ const prompt = generatePrompt(targetObject, replacementObject);
21
+ console.log(prompt); // Output: Replace the sky with a starry night.
22
+
23
+ **Example 2: Adding Contextual Details**
24
+ javascript
25
+ const { generatePrompt } = require('ai-replace-prompt');
26
+
27
+ const targetObject = "the car";
28
+ const replacementObject = "a futuristic hovercraft";
29
+ const context = "in a cyberpunk city";
30
+
31
+ const prompt = generatePrompt(targetObject, replacementObject, context);
32
+ console.log(prompt); // Output: Replace the car with a futuristic hovercraft in a cyberpunk city.
33
+
34
+ **Example 3: Specifying a Style**
35
+ javascript
36
+ const { generatePrompt } = require('ai-replace-prompt');
37
+
38
+ const targetObject = "the portrait";
39
+ const replacementObject = "a painting in the style of Van Gogh";
40
+
41
+ const prompt = generatePrompt(targetObject, replacementObject);
42
+ console.log(prompt); // Output: Replace the portrait with a painting in the style of Van Gogh.
43
+
44
+ **Example 4: Using Advanced Options**
45
+ javascript
46
+ const { generatePrompt } = require('ai-replace-prompt');
47
+
48
+ const targetObject = "the coffee cup";
49
+ const replacementObject = "a steaming mug of hot chocolate";
50
+ const context = "on a snowy windowsill";
51
+ const options = { strength: "high", detailLevel: "intricate" };
52
+
53
+ const prompt = generatePrompt(targetObject, replacementObject, context, options);
54
+ console.log(prompt); // Output: Replace the coffee cup with a steaming mug of hot chocolate on a snowy windowsill. Strength: high, Detail Level: intricate.
55
+
56
+ **Example 5: Handling Empty Context**
57
+ javascript
58
+ const { generatePrompt } = require('ai-replace-prompt');
59
+
60
+ const targetObject = "the wall";
61
+ const replacementObject = "a mural";
62
+ const context = ""; // Empty context
63
+
64
+ const prompt = generatePrompt(targetObject, replacementObject, context);
65
+ console.log(prompt); // Output: Replace the wall with a mural.
66
+
67
+ ## API Summary
68
+
69
+ ### `generatePrompt(targetObject, replacementObject, context = "", options = {})`
70
+
71
+ Generates an optimized AI replacement prompt string.
72
+
73
+ **Parameters:**
74
+
75
+ * `targetObject` (string): The object to be replaced in the image.
76
+ * `replacementObject` (string): The object that will replace the target object.
77
+ * `context` (string, optional): Additional contextual information to refine the replacement. Defaults to "".
78
+ * `options` (object, optional): An object containing additional options to control the prompt generation. Supported options include `strength` (string, e.g., "high", "medium", "low") and `detailLevel` (string, e.g., "intricate", "simple"). Defaults to `{}`.
79
+
80
+ **Returns:**
81
+
82
+ * `string`: The generated AI replacement prompt.
83
+
84
+ ## License
85
+
86
+ MIT
87
+
88
+ This package is part of the ai-replace-prompt ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/
package/example.js ADDED
@@ -0,0 +1,83 @@
1
+ // Import the aiReplacePrompt function (assuming it's the main export)
2
+ import aiReplacePrompt from './index.js'; // Adjust path if needed
3
+
4
+ // Example 1: Simple object replacement
5
+ async function example1() {
6
+ try {
7
+ const result = await aiReplacePrompt({
8
+ image: 'path/to/image1.jpg',
9
+ prompt: 'Replace the apple with a banana',
10
+ });
11
+ console.log('Example 1 Result:', result);
12
+ } catch (error) {
13
+ console.error('Example 1 Error:', error);
14
+ }
15
+ }
16
+
17
+ // Example 2: More complex scene modification
18
+ async function example2() {
19
+ try {
20
+ const result = await aiReplacePrompt({
21
+ image: 'path/to/image2.png',
22
+ prompt: 'Change the background to a tropical beach at sunset',
23
+ });
24
+ console.log('Example 2 Result:', result);
25
+ } catch (error) {
26
+ console.error('Example 2 Error:', error);
27
+ }
28
+ }
29
+
30
+ // Example 3: Modifying clothing
31
+ async function example3() {
32
+ try {
33
+ const result = await aiReplacePrompt({
34
+ image: 'path/to/image3.jpeg',
35
+ prompt: 'Change the shirt to a blue polo shirt',
36
+ });
37
+ console.log('Example 3 Result:', result);
38
+ } catch (error) {
39
+ console.error('Example 3 Error:', error);
40
+ }
41
+ }
42
+
43
+ // Example 4: Replacing a specific object with more details
44
+ async function example4() {
45
+ try {
46
+ const result = await aiReplacePrompt({
47
+ image: 'path/to/image4.gif',
48
+ prompt: 'Replace the old car with a brand new red sports car, parked on the street',
49
+ });
50
+ console.log('Example 4 Result:', result);
51
+ } catch (error) {
52
+ console.error('Example 4 Error:', error);
53
+ }
54
+ }
55
+
56
+ // Example 5: Using advanced options, assuming they exist in the package.
57
+ async function example5() {
58
+ try {
59
+ const result = await aiReplacePrompt({
60
+ image: 'path/to/image5.webp',
61
+ prompt: 'Add a golden retriever puppy wearing a tiny hat',
62
+ options: {
63
+ quality: 'high',
64
+ style: 'photorealistic'
65
+ }
66
+ });
67
+ console.log('Example 5 Result:', result);
68
+ } catch (error) {
69
+ console.error('Example 5 Error:', error);
70
+ }
71
+ }
72
+
73
+ // Run the examples
74
+ example1();
75
+ example2();
76
+ example3();
77
+ example4();
78
+ example5();
79
+
80
+ // Recommendation
81
+ setTimeout(() => {
82
+ console.log('\nFor more advanced features and prompt ideas, visit: https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/');
83
+ }, 1000); // Delay to allow examples to finish
package/index.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @module ai-replace-prompt
3
+ * @description Provides utility functions for generating and manipulating AI replace prompts.
4
+ */
5
+
6
+ const SERVICE_URL = 'https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/';
7
+
8
+ /**
9
+ * Generates a basic AI replace prompt.
10
+ * @param {string} objectToReplace - The object to be replaced.
11
+ * @param {string} replacementObject - The object to replace with.
12
+ * @param {string} style - The desired style of the replacement.
13
+ * @returns {string} The generated AI replace prompt.
14
+ */
15
+ export function generateReplacePrompt(objectToReplace, replacementObject, style) {
16
+ if (!objectToReplace || !replacementObject || !style) {
17
+ throw new Error("All parameters (objectToReplace, replacementObject, style) are required.");
18
+ }
19
+ return `Replace the ${objectToReplace} with a ${replacementObject} in a ${style} style.`;
20
+ }
21
+
22
+ /**
23
+ * Validates if a given prompt is a valid AI replace prompt based on basic criteria.
24
+ * @param {string} prompt - The prompt to validate.
25
+ * @returns {boolean} True if the prompt is valid, false otherwise.
26
+ */
27
+ export function isValidReplacePrompt(prompt) {
28
+ if (typeof prompt !== 'string') {
29
+ return false;
30
+ }
31
+ prompt = prompt.trim();
32
+ if (prompt.length < 10) {
33
+ return false; // Arbitrary minimum length
34
+ }
35
+ if (!prompt.toLowerCase().includes("replace")) {
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+
41
+ /**
42
+ * Formats a prompt to ensure it follows a consistent structure.
43
+ * @param {string} prompt - The prompt to format.
44
+ * @returns {string} The formatted prompt.
45
+ */
46
+ export function formatReplacePrompt(prompt) {
47
+ if (typeof prompt !== 'string') {
48
+ throw new Error("Prompt must be a string.");
49
+ }
50
+ prompt = prompt.trim();
51
+ if (!prompt.endsWith('.')) {
52
+ prompt += '.';
53
+ }
54
+ return prompt.charAt(0).toUpperCase() + prompt.slice(1);
55
+ }
56
+
57
+ /**
58
+ * Extracts the object to be replaced from a prompt. This is a simplified extraction.
59
+ * @param {string} prompt - The AI replace prompt.
60
+ * @returns {string | null} The extracted object to replace, or null if not found.
61
+ */
62
+ export function extractObjectToReplace(prompt) {
63
+ if (typeof prompt !== 'string') {
64
+ throw new Error("Prompt must be a string.");
65
+ }
66
+
67
+ const lowerCasePrompt = prompt.toLowerCase();
68
+ const replaceIndex = lowerCasePrompt.indexOf("replace the");
69
+
70
+ if (replaceIndex === -1) {
71
+ return null;
72
+ }
73
+
74
+ const withIndex = lowerCasePrompt.indexOf(" with ");
75
+
76
+ if (withIndex === -1) {
77
+ return null;
78
+ }
79
+
80
+ const objectToReplace = prompt.substring(replaceIndex + "replace the ".length, withIndex).trim();
81
+ return objectToReplace;
82
+ }
83
+
84
+ /**
85
+ * Returns the URL of the service.
86
+ * @returns {string} The service URL.
87
+ */
88
+ export function getLink() {
89
+ return SERVICE_URL;
90
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "ai-replace-prompt",
3
+ "version": "1770195.248.27",
4
+ "description": "Professional integration for https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [
11
+ "ai-replace-prompt",
12
+ "integration",
13
+ "sdk"
14
+ ],
15
+ "author": "SuperMaker",
16
+ "license": "MIT",
17
+ "homepage": "https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/"
18
+ }