The `connection-string-parser` library provides a generic, cross-environment solution for converting URI-based connection strings into structured JSON objects and vice-versa. It supports both Node.js and browser environments, addressing a common problem where applications need to consume compact URI strings (e.g., `mongodb://user:pass@host/db?options`) but underlying connection tools require a JSON configuration object. The current stable version is 1.0.4. The library is written in TypeScript and ships with type definitions. It differentiates itself by offering a flexible, scheme-agnostic parsing mechanism, allowing developers to define custom URI patterns beyond standard database connection strings, making it suitable for various project-specific configurations. Its release cadence appears to be stable, focusing on robust utility.
npm install connection-string-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the parser with a scheme and parse a URI-encoded connection string into a structured connection object, showing key components like scheme, hosts, credentials, and options.
Before constructing the full connection string, ensure all variable parts are passed through `encodeURIComponent()`. For example, `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@...`Always ensure the `scheme` property provided during `ConnectionStringParser` instantiation exactly matches the scheme of the connection string you intend to parse. Validate the output object for completeness.
Refer to the official GitHub repository or source code for examples and detailed usage of the `format` method, if you need to convert a connection object back into a connection string.
Manually apply `encodeURIComponent()` to each non-literal component (username, password, database, options values) of your connection string before passing the complete string to the parser. Ensure the overall string follows the expected URI format.
Verify that the `ConnectionStringParser` instance was configured with the correct `scheme` matching the input string. Always check the returned object for existence and expected structure before accessing its properties.
No dependency data recorded yet.