# All files / lib/serialization cid.js

100% Statements 27/27
90% Branches 9/10
100% Functions 8/8
100% Lines 27/27

    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58

    1x

    1x

    1x

    1x

    1x

    1x

    1x
    33x

    1x
    33x

    1x
    1x
    72x

    1x
    418x
    72x
    98x

    72x
    14x

    72x

    1x
    418x
    72x
    98x

    72x
    14x

    72x

     'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.preCidToJson = exports.preCidFromJson = exports.isCidJson = exports.isCid = exports.cidToJson = exports.cidFromJson = undefined;

    var _cids = require('cids');

    var _cids2 = _interopRequireDefault(_cids);

    var _buffer = require('./buffer');

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

    var cidFromJson = exports.cidFromJson = function cidFromJson(obj) {
      return new _cids2.default(obj.version, obj.codec, (0, _buffer.bufferFromJson)(obj.hash));
    };

    var cidToJson = exports.cidToJson = function cidToJson(cid) {
      return {
        __ipfsPostMsgProxyType: 'CID',
        codec: cid.codec,
        version: cid.version,
        hash: (0, _buffer.bufferToJson)(cid.multihash)
      };
    };

    var isCid = exports.isCid = _cids2.default.isCID;
    var isCidJson = exports.isCidJson = function isCidJson(obj) {
      return obj && obj.__ipfsPostMsgProxyType === 'CID';
    };

    var preCidFromJson = exports.preCidFromJson = function preCidFromJson(index) {
      return function () {
        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        if (isCidJson(args[index])) {
          args[index] = cidFromJson(args[index]);
        }
        return args;
      };
    };

    var preCidToJson = exports.preCidToJson = function preCidToJson(index) {
      return function () {
        for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
          args[_key2] = arguments[_key2];
        }

        if (isCid(args[index])) {
          args[index] = cidToJson(args[index]);
        }
        return args;
      };
    };