Registry / http-networking / replace-url-values

replace-url-values

JSON →
library1.0.0jsnpmunverified

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.

npm install replace-url-values
INSTALL
IMPORT
SIG · REPLACE-URL-VALUES
R
replace-url-values
http-networkingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

replaceUrlValues
import { replaceUrlValues } from 'replace-url-values';
const replaceUrlValues = require('replace-url-values');
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.
replaceUrlValues
import replaceUrlValues from 'replace-url-values';
import { replaceUrlValues } from 'replace-url-values';
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.
All exports
import * as UrlReplacer from 'replace-url-values';
Useful for accessing all exported utilities under a namespace, if multiple functions are exposed. This assumes named exports.

Demonstrates replacing both path placeholders and query parameters in a URL string, including adding new parameters and handling URL encoding of replacement values.

import { replaceUrlValues } from 'replace-url-values'; // Example 1: Replacing placeholders in a URL path like '/products/:productId' const urlTemplateWithPathParams = '/products/:productId/reviews/:reviewId'; const pathReplacements = { productId: '456', reviewId: '789' }; const finalUrl1 = replaceUrlValues(urlTemplateWithPathParams, pathReplacements); console.log('Replaced path URL:', finalUrl1); // Expected output: /products/456/reviews/789 // Example 2: Replacing specific query parameter values in an existing URL const urlWithQueryParams = 'https://example.com/search?q=apple&page=1'; const queryReplacements = { q: 'banana and orange', // Replace existing 'q' page: '2', // Replace existing 'page' sort: 'desc' // Add a new parameter 'sort' }; const finalUrl2 = replaceUrlValues(urlWithQueryParams, queryReplacements); console.log('Replaced query params URL:', finalUrl2); // Expected output (order might vary, but parameters should be correct): // https://example.com/search?q=banana%20and%20orange&page=2&sort=desc // Example 3: Handling missing placeholders gracefully (assumption: no change for unmatched keys) const incompleteTemplate = '/users/:userId/profile'; const partialReplacements = { userId: '101' }; const finalUrl3 = replaceUrlValues(incompleteTemplate, partialReplacements); console.log('Partial replacements:', finalUrl3); // Expected output: /users/101/profile // Example 4: When no matches are found, the original URL is returned (assumption) const noMatchUrl = 'https://example.com/data'; const noMatchReplacements = { unknownKey: 'value' }; const finalUrl4 = replaceUrlValues(noMatchUrl, noMatchReplacements); console.log('No matches:', finalUrl4);
Debug
Known issues
gotchaWhen 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.
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.
affects: >=1.0.0
gotchaURL 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.
fix
Store the result of `replaceUrlValues` in a new variable: `const newUrl = replaceUrlValues(originalUrl, replacements);`
affects: >=1.0.0
gotchaBe 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: replaceUrlValues is not a function
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.
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.
URIError: URI malformed
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.
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.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
replace-url-values — npm install replace-url-values · libregistry