包详细信息

connection-parse

3rd-Eden805.9kMIT0.0.7

Simple TCP connection string parser

TCP, connection, parser, connection-string

自述文件

connection-parse

Simple TCP connection string parser, and nothing more then that. It simply transforms 1.1.1.1:1111 in to a simple parsed object. I seem to do this a lot in most of my modules such as hashring, memcached and failover. So it makes sense to extract this in to a small util.

Installation

Install this module using npm:

npm install connection-parse --save

The --save automatically adds the package and version to your package.json.

API

var parse = require('connection-parse');

parse('1.1.1.1:1111')
parse('1.1.1.1:1111', '1.3.3.4:1345');
parse(['1.1.1.1:1111', '1.3.3.4:1345']);
parse({ '1.1.1.1:1111': 100 });

{
  servers: [{
    string: '1.1.1.1:1111',
    host: '1.1.1.1',
    port: 1111
  }],
  regular: ['1.1.1.1:1111'],
  weighted: {
    '1.1.1.1:1111': 100 // or 1 by default
  }
}

// It also accepts custom parsers
parse.merge(function (data) {
  data.foo = 'bar';
  return data;
});

Then the server instances will also have an extra property, `foo`.

License

MIT

更新日志

0.0.6

  • Default to no weight
  • Fixed a bug that set the default weight to the index of the array.

0.0.5

  • Fixed a bug where the weight was not parse correctly when multipe values were provided in an object, but no weight.

0.0.4

  • Don't die when we parse without arguments.

0.0.3

  • Added support for custom parsers.

0.0.2

  • Added length property

0.0.1

  • Added the weight property to parsed server instance

0.0.0

  • Initial release