Swap-Aggregator-Subgraph/node_modules/dockerode/lib/util.js
Richa-iitr d211083153 Revert "Revert "added handler""
This reverts commit c36ee8c5ca.
2022-07-03 07:30:05 +05:30

71 lines
1.7 KiB
JavaScript

// https://github.com/HenrikJoreteg/extend-object/blob/v0.1.0/extend-object.js
var arr = [];
var each = arr.forEach;
var slice = arr.slice;
module.exports.extend = function(obj) {
each.call(slice.call(arguments, 1), function(source) {
if (source) {
for (var prop in source) {
obj[prop] = source[prop];
}
}
});
return obj;
};
module.exports.processArgs = function(opts, callback, defaultOpts) {
if (!callback && typeof opts === 'function') {
callback = opts;
opts = null;
}
return {
callback: callback,
opts: module.exports.extend({}, defaultOpts, opts)
};
};
/**
* Parse the given repo tag name (as a string) and break it out into repo/tag pair.
* // if given the input http://localhost:8080/woot:latest
* {
* repository: 'http://localhost:8080/woot',
* tag: 'latest'
* }
* @param {String} input Input e.g: 'repo/foo', 'ubuntu', 'ubuntu:latest'
* @return {Object} input parsed into the repo and tag.
*/
module.exports.parseRepositoryTag = function(input) {
var separatorPos;
var digestPos = input.indexOf('@');
var colonPos = input.lastIndexOf(':');
// @ symbol is more important
if (digestPos >= 0) {
separatorPos = digestPos;
} else if (colonPos >= 0) {
separatorPos = colonPos;
} else {
// no colon nor @
return {
repository: input
};
}
// last colon is either the tag (or part of a port designation)
var tag = input.slice(separatorPos + 1);
// if it contains a / its not a tag and is part of the url
if (tag.indexOf('/') === -1) {
return {
repository: input.slice(0, separatorPos),
tag: tag
};
}
return {
repository: input
};
};