{"id":12994,"library":"connection-parse","title":"TCP Connection String Parser","description":"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.","status":"abandoned","version":"0.0.7","language":"javascript","source_language":"en","source_url":"git://github.com/3rd-Eden/connection-parse","tags":["javascript","TCP","connection","parser","connection-string"],"install":[{"cmd":"npm install connection-parse","lang":"bash","label":"npm"},{"cmd":"yarn add connection-parse","lang":"bash","label":"yarn"},{"cmd":"pnpm add connection-parse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail.","wrong":"import parse from 'connection-parse';","symbol":"parse","correct":"const parse = require('connection-parse');"},{"note":"The `merge` function is a method on the default CommonJS export, not a named export. It is not available via ESM.","wrong":"import { merge } from 'connection-parse';","symbol":"parse.merge","correct":"const parse = require('connection-parse');\nparse.merge((data) => { /* ... */ });"},{"note":"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 } }`.","symbol":"ParsedConnectionObject","correct":"// No direct type import available; define manually if needed."}],"quickstart":{"code":"const parse = require('connection-parse');\n\n// Basic parsing of a single connection string\nconst singleServer = parse('1.1.1.1:1111');\nconsole.log('Single Server:', JSON.stringify(singleServer, null, 2));\n\n// Parsing multiple connection strings from an array\nconst multipleServers = parse(['1.1.1.1:1111', '1.3.3.4:1345']);\nconsole.log('\\nMultiple Servers:', JSON.stringify(multipleServers, null, 2));\n\n// Parsing with weights\nconst weightedServers = parse({ '2.2.2.2:2222': 50, '3.3.3.3:3333': 100 });\nconsole.log('\\nWeighted Servers:', JSON.stringify(weightedServers, null, 2));\n\n// Adding a custom merge function\nparse.merge(function (data) {\n  data.environment = process.env.NODE_ENV ?? 'development';\n  return data;\n});\n\nconst customParsed = parse('1.1.1.1:1111');\nconsole.log('\\nCustom Parsed (with environment):', JSON.stringify(customParsed, null, 2));","lang":"javascript","description":"Demonstrates basic TCP connection string parsing for single, multiple, and weighted servers, including extending output with a custom `merge` function."},"warnings":[{"fix":"Use `const parse = require('connection-parse');` instead of `import parse from 'connection-parse';` in your code.","message":"This package is entirely CommonJS (CJS) and does not provide ES Module (ESM) exports. Attempting to use `import` statements will result in runtime errors.","severity":"breaking","affected_versions":">=0.0.1"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.1"},{"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).","message":"There 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.","severity":"gotcha","affected_versions":">=0.0.1"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using the correct CommonJS import for the default export: `const parse = require('connection-parse');`","cause":"Attempting to access `parse.merge` after an incorrect ESM import like `import { merge } from 'connection-parse';`.","error":"TypeError: Cannot read properties of undefined (reading 'merge')"},{"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.","cause":"Trying to `require()` an ES Module or using `import` for a CommonJS-only package in an ESM context.","error":"ERR_REQUIRE_ESM"},{"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.","cause":"TypeScript error when accessing properties added by a custom `parse.merge` function, because the package lacks type definitions.","error":"Property 'environment' does not exist on type '{ servers: ... }'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}