# All files / serialization multiaddr.js

30.43% Statements 7/23
0% Branches 0/8
0% Functions 0/8
46.67% Lines 7/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    301x

    1x

    1x

    1x
    1x

    1x

    1x

     import Multiaddr from 'multiaddr'

    export const multiaddrFromJson = (obj) => new Multiaddr(obj.multiaddr)

    export const multiaddrToJson = (multiaddr) => ({
      __ipfsPostMsgProxyType: 'Multiaddr',
      multiaddr: multiaddr.toString()
    })

    export const isMultiaddr = (obj) => obj && Multiaddr.isMultiaddr(obj)
    export const isMultiaddrJson = (obj) => obj && obj.__ipfsPostMsgProxyType === 'Multiaddr'

    export const preMultiaddrFromJson = (index) => {
      return (...args) => {
        if (isMultiaddrJson(args[index])) {
          args[index] = multiaddrFromJson(args[index])
        }
        return args
      }
    }

    export const preMultiaddrToJson = (index) => {
      return (...args) => {
        if (isMultiaddr(args[index])) {
          args[index] = multiaddrToJson(args[index])
        }
        return args
      }
    }