Registry / http-networking / connection-parse

connection-parse

JSON →
library0.0.7jsnpmunverified

connection-parse is a lightweight utility designed to parse TCP connection strings, transforming formats like `1.1.1.1:1111` into structured objects containing `host`, `port`, and the original `string`. It also supports parsing multiple connection strings from arrays, arguments, or weighted object formats, and allows for custom merge functions to extend the parsed data. Originally extracted from common logic in other modules, its primary purpose is simplifying the handling of server addresses. The package is currently at version 0.0.7, with its last publish occurring over nine years ago, indicating it is an abandoned project with no active development or maintenance. Users should be aware of its unmaintained status and consider modern alternatives for new projects, as it lacks contemporary features like ESM support and TypeScript typings.

npm install connection-parse
INSTALL
IMPORT
SIG · CONNECTION-PARSE
C
connection-parse
http-networkingjavascriptv0.0.7
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

parse
✓ const parse = require('connection-parse');
✗ import parse from 'connection-parse';
This package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail.
parse.merge
✓ const parse = require('connection-parse'); parse.merge((data) => { /* ... */ });
✗ import { merge } from 'connection-parse';
The `merge` function is a method on the default CommonJS export, not a named export. It is not available via ESM.
ParsedConnectionObject
✓ // No direct type import available; define manually if needed.
This package does not ship with TypeScript type definitions. Users need to define their own interfaces for the parsed connection objects, e.g., `{ servers: { string: string, host: string, port: number }[], regular: string[], weighted: { [key: string]: number } }`.

Demonstrates basic TCP connection string parsing for single, multiple, and weighted servers, including extending output with a custom `merge` function.

const parse = require('connection-parse'); // Basic parsing of a single connection string const singleServer = parse('1.1.1.1:1111'); console.log('Single Server:', JSON.stringify(singleServer, null, 2)); // Parsing multiple connection strings from an array const multipleServers = parse(['1.1.1.1:1111', '1.3.3.4:1345']); console.log('\nMultiple Servers:', JSON.stringify(multipleServers, null, 2)); // Parsing with weights const weightedServers = parse({ '2.2.2.2:2222': 50, '3.3.3.3:3333': 100 }); console.log('\nWeighted Servers:', JSON.stringify(weightedServers, null, 2)); // Adding a custom merge function parse.merge(function (data) { data.environment = process.env.NODE_ENV ?? 'development'; return data; }); const customParsed = parse('1.1.1.1:1111'); console.log('\nCustom Parsed (with environment):', JSON.stringify(customParsed, null, 2));
Debug
Known issues
breakingThis package is entirely CommonJS (CJS) and does not provide ES Module (ESM) exports. Attempting to use `import` statements will result in runtime errors.
fix
Use `const parse = require('connection-parse');` instead of `import parse from 'connection-parse';` in your code.
affects: >=0.0.1
gotchaThe package is not actively maintained, with the last publish over 9 years ago. This means it will not receive updates for bug fixes, security vulnerabilities, or new features.
fix
For new projects, consider using a more modern and actively maintained parsing library or implement the simple parsing logic yourself. For existing projects, audit its usage carefully.
affects: >=0.0.1
gotchaThere are no official TypeScript type definitions (`.d.ts` files) included with this package. This can lead to poor developer experience and type safety issues in TypeScript projects.
fix
You will need to create a declaration file (e.g., `connection-parse.d.ts`) or use a tool like `@types/connection-parse` if one exists (unlikely given its age), or suppress type errors with `@ts-ignore` (not recommended).
affects: >=0.0.1
gotchaThe `parse.merge` function mutates a global internal parser function. Subsequent calls to `parse` will apply the last merged function, which can lead to unexpected side effects if not managed carefully.
fix
Be mindful of where and how `parse.merge` is called. If different parsing behaviors are needed, ensure the merge function is reset or reconfigured appropriately, or avoid using `parse.merge` if global state mutation is problematic.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'merge')
Attempting to access `parse.merge` after an incorrect ESM import like `import { merge } from 'connection-parse';`.
fix
Ensure you are using the correct CommonJS import for the default export: `const parse = require('connection-parse');`
ERR_REQUIRE_ESM
Trying to `require()` an ES Module or using `import` for a CommonJS-only package in an ESM context.
fix
This package is CommonJS-only. If your project is ESM, you must use a dynamic import workaround (`import('connection-parse')`) or convert your file to CommonJS. However, given the package's abandoned status, migrating to a modern alternative is recommended.
Property 'environment' does not exist on type '{ servers: ... }'
TypeScript error when accessing properties added by a custom `parse.merge` function, because the package lacks type definitions.
fix
Create a custom type declaration for `connection-parse` or cast the result of `parse` to an `any` type (less recommended) to inform TypeScript about the added properties.
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
connection-parse — npm install connection-parse · libregistry