ipfs-http-client
Version:
A client library for the IPFS HTTP API
52 lines (45 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var errCode = require('err-code');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var errCode__default = /*#__PURE__*/_interopDefaultLegacy(errCode);
function parseMtime(input) {
if (input == null) {
return undefined;
}
let mtime;
if (input.secs != null) {
mtime = {
secs: input.secs,
nsecs: input.nsecs
};
}
if (input.Seconds != null) {
mtime = {
secs: input.Seconds,
nsecs: input.FractionalNanoseconds
};
}
if (Array.isArray(input)) {
mtime = {
secs: input[0],
nsecs: input[1]
};
}
if (input instanceof Date) {
const ms = input.getTime();
const secs = Math.floor(ms / 1000);
mtime = {
secs: secs,
nsecs: (ms - secs * 1000) * 1000
};
}
if (!Object.prototype.hasOwnProperty.call(mtime, 'secs')) {
return undefined;
}
if (mtime != null && mtime.nsecs != null && (mtime.nsecs < 0 || mtime.nsecs > 999999999)) {
throw errCode__default["default"](new Error('mtime-nsecs must be within the range [0,999999999]'), 'ERR_INVALID_MTIME_NSECS');
}
return mtime;
}
exports.parseMtime = parseMtime;