1.2.0 • Published 5 years ago

ni-uri v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

NI-URI

Parsing, formatting and digesting utilities for Named Information (NI) URIs in Node.js land.

Usage

install / require

$ npm install ni-uri

const ni = require('ni-uri');

.format(Object parts)

Similar to Node.js' url#format().

const result = ni.format({
  host: example.com,
  algorithm: 'sha-256',
  value: '71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w',
  query: {q: '1'}
});

// 'ni://example.con/sha-256;71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w?q=1'

.parse(string uri, boolean parseQuery)

Similar to Node.js' url#parse().

const result = ni.parse('ni://example.con/sha-256;71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w?q=1', true);
 
// {
//   protocol: 'ni',
//   algorithm: 'sha-256',
//   value: '71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w',
//   host: 'example.com'
// }

.digest(string algorithm, string | Buffer data, string encoding, Object | boolean parts)

Generates the hash/value component for some data. Returns the hash or a formatted uri.

const result = ni.digest('sha-256', 'The quick brown fox jumps over the lazy dog.');

// returns '71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w'

const result = ni.digest('sha-256', 'The quick brown fox jumps over the lazy dog.', true);

// returns 'ni:///sha-256;71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w'

const result = ni.digest('sha-256', 'The quick brown fox jumps over the lazy dog.', {host: 'example.com'});

// returns 'ni://example.com/sha-256;71N_JciVv6eCUmUpqbY9l6pjFWTV14nCt2VEjIY1-2w'

.isAlgorithm(string algorithm)

Returns true if the string identifies a supported digest algorithm, false otherwise.

To-Do

  • support for human-friendly nih:// format
  • support for hash truncation

License

MIT - see LICENSE.md.

1.2.0

5 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago