js-ipld-url

1.0.2 • Public • Published

js-ipld-url

Parser and serializer for IPLD URLs in JavaScript

Works in the browser, Node.js 16+, and Deno 1.23+

Example

import IPLDURL, {IPLDURLSegment} from './ipldurl.js'

const url = new IPLDURL('ipld://examplecidhere/path;param1=value1/to/thing;param2;param3=value2/?queryparam=whatever

const segments = url.segments

segments === [{
  name: 'path',
  parameters: {param1: 'value1'}
}, {
  name: 'to'
}, {
  name: 'thing',
  parameters: {parm2:'', param3: 'value2'}
}]

// Set segments programmatically
url.segments = [{
  // Automatically escape special characters in the name
  name: 'escape;this',
  // Split up arrays into multiple params
  parameters: {whatever:[1,2,3]}
}, {
  name: '😁'
}]

url.href === 'ipld://examplecidhere/escape%3Bthis;whatever=1;whatever=2;whatever=3/%F0%9F%98%81?queryparam=whatever'

/js-ipld-url/

    Package Sidebar

    Install

    npm i js-ipld-url

    Weekly Downloads

    12

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    12.2 kB

    Total Files

    5

    Last publish

    Collaborators

    • rangermauve