# All files / src/serialization multiaddr.js

91.3% Statements 21/23
75% Branches 6/8
100% Functions 8/8
86.67% Lines 13/15

    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

    117x

    117x

    16x
    16x

    1x
    46x
    16x

    16x

    1x
    46x
    16x

    16x

     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) => {
        Iif (isMultiaddrJson(args[index])) {
          args[index] = multiaddrFromJson(args[index])
        }
        return args
      }
    }

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