{"id":14889,"library":"replace-url-values","title":"URL Value Replacer","description":"The `replace-url-values` package, currently at version `1.0.0`, is designed as a focused utility to programmatically substitute specified values within a given URL string. It likely facilitates the dynamic generation of URLs by replacing placeholders in path segments (e.g., `:id`) or modifying existing query parameters. While specific details about its API and internal mechanisms are not publicly available through a readily identifiable npm registry entry or a public GitHub repository at the provided link, such utilities typically offer a simple function to map specific keys to their desired replacement values, returning a new URL string. The package is noted to ship with TypeScript types, suggesting good integration for type-safe development environments. Due to the lack of public information, its release cadence and key differentiators beyond its core functionality remain unclear, but it aims to provide a straightforward approach to a common web development task.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sharongrossman/replace-url-values","tags":["javascript","typescript"],"install":[{"cmd":"npm install replace-url-values","lang":"bash","label":"npm"},{"cmd":"yarn add replace-url-values","lang":"bash","label":"yarn"},{"cmd":"pnpm add replace-url-values","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is assumed to primarily offer a named export 'replaceUrlValues' for its core functionality, given its TypeScript support and common patterns for modern JavaScript utilities. CommonJS require is likely not supported directly without bundler configuration.","wrong":"const replaceUrlValues = require('replace-url-values');","symbol":"replaceUrlValues","correct":"import { replaceUrlValues } from 'replace-url-values';"},{"note":"If the package uses a default export, this would be the correct syntax. Verify package.json 'type' field and export style if available, as 'replace-url-values' might use a default export.","wrong":"import { replaceUrlValues } from 'replace-url-values';","symbol":"replaceUrlValues","correct":"import replaceUrlValues from 'replace-url-values';"},{"note":"Useful for accessing all exported utilities under a namespace, if multiple functions are exposed. This assumes named exports.","symbol":"All exports","correct":"import * as UrlReplacer from 'replace-url-values';"}],"quickstart":{"code":"import { replaceUrlValues } from 'replace-url-values';\n\n// Example 1: Replacing placeholders in a URL path like '/products/:productId'\nconst urlTemplateWithPathParams = '/products/:productId/reviews/:reviewId';\nconst pathReplacements = {\n  productId: '456',\n  reviewId: '789'\n};\nconst finalUrl1 = replaceUrlValues(urlTemplateWithPathParams, pathReplacements);\nconsole.log('Replaced path URL:', finalUrl1);\n// Expected output: /products/456/reviews/789\n\n// Example 2: Replacing specific query parameter values in an existing URL\nconst urlWithQueryParams = 'https://example.com/search?q=apple&page=1';\nconst queryReplacements = {\n  q: 'banana and orange', // Replace existing 'q'\n  page: '2',              // Replace existing 'page'\n  sort: 'desc'            // Add a new parameter 'sort'\n};\nconst finalUrl2 = replaceUrlValues(urlWithQueryParams, queryReplacements);\nconsole.log('Replaced query params URL:', finalUrl2);\n// Expected output (order might vary, but parameters should be correct):\n// https://example.com/search?q=banana%20and%20orange&page=2&sort=desc\n\n// Example 3: Handling missing placeholders gracefully (assumption: no change for unmatched keys)\nconst incompleteTemplate = '/users/:userId/profile';\nconst partialReplacements = { userId: '101' };\nconst finalUrl3 = replaceUrlValues(incompleteTemplate, partialReplacements);\nconsole.log('Partial replacements:', finalUrl3);\n// Expected output: /users/101/profile\n\n// Example 4: When no matches are found, the original URL is returned (assumption)\nconst noMatchUrl = 'https://example.com/data';\nconst noMatchReplacements = { unknownKey: 'value' };\nconst finalUrl4 = replaceUrlValues(noMatchUrl, noMatchReplacements);\nconsole.log('No matches:', finalUrl4);","lang":"typescript","description":"Demonstrates replacing both path placeholders and query parameters in a URL string, including adding new parameters and handling URL encoding of replacement values."},"warnings":[{"fix":"Always pass raw, unencoded string values to the replacement function. The library should handle encoding automatically. If not, manually encode values using `encodeURIComponent()` before passing them.","message":"When replacing values, ensure that the new values are correctly URL-encoded, especially if they contain special characters or spaces. While the utility is expected to handle this automatically, improper input can lead to malformed URLs or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Store the result of `replaceUrlValues` in a new variable: `const newUrl = replaceUrlValues(originalUrl, replacements);`","message":"URL objects are often immutable in browsers and Node.js (e.g., `URL` API). This utility is expected to return a *new* string or URL instance after replacement, rather than modifying the input URL object in place. Always assign the return value.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test complex URL patterns thoroughly. Review the library's source code or documentation (if it becomes available) for exact parsing and replacement rules. Consider using more distinct placeholder names in templates.","message":"Be mindful of ambiguous placeholder patterns (e.g., multiple ':' characters, or similar query parameter keys). The specific replacement logic for complex URL structures might have edge cases not immediately obvious from a simple API.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Try importing as a default export: `import replaceUrlValues from 'replace-url-values';` or verify the correct named export from the package's documentation/source code. Ensure the package is installed correctly.","cause":"The 'replaceUrlValues' function was not correctly imported or does not exist as a named export. This can happen if the package uses a default export, or if the import path is incorrect.","error":"TypeError: replaceUrlValues is not a function"},{"fix":"Inspect the input URL and all replacement values for invalid characters or malformed segments that could prevent proper parsing or encoding. Ensure all string inputs are well-formed before passing them to the utility.","cause":"This error typically occurs if a string passed to an internal URL encoding/decoding function is not valid. It might indicate that the input URL or a replacement value caused an intermediate malformed URI.","error":"URIError: URI malformed"}],"ecosystem":"npm"}