UNPKG

1.69 kBJavaScriptView Raw
1// https://github.com/HenrikJoreteg/extend-object/blob/v0.1.0/extend-object.js
2
3var arr = [];
4var each = arr.forEach;
5var slice = arr.slice;
6
7module.exports.extend = function(obj) {
8 each.call(slice.call(arguments, 1), function(source) {
9 if (source) {
10 for (var prop in source) {
11 obj[prop] = source[prop];
12 }
13 }
14 });
15 return obj;
16};
17
18module.exports.processArgs = function(opts, callback, defaultOpts) {
19 if (!callback && typeof opts === 'function') {
20 callback = opts;
21 opts = null;
22 }
23 return {
24 callback: callback,
25 opts: module.exports.extend({}, defaultOpts, opts)
26 };
27};
28
29
30/**
31 * Parse the given repo tag name (as a string) and break it out into repo/tag pair.
32 * // if given the input http://localhost:8080/woot:latest
33 * {
34 * repository: 'http://localhost:8080/woot',
35 * tag: 'latest'
36 * }
37 * @param {String} input Input e.g: 'repo/foo', 'ubuntu', 'ubuntu:latest'
38 * @return {Object} input parsed into the repo and tag.
39 */
40module.exports.parseRepositoryTag = function(input) {
41 var separatorPos;
42 var digestPos = input.indexOf('@');
43 var colonPos = input.lastIndexOf(':');
44 // @ symbol is more important
45 if (digestPos >= 0) {
46 separatorPos = digestPos;
47 } else if (colonPos >= 0) {
48 separatorPos = colonPos;
49 } else {
50 // no colon nor @
51 return {
52 repository: input
53 };
54 }
55
56 // last colon is either the tag (or part of a port designation)
57 var tag = input.slice(separatorPos + 1);
58
59 // if it contains a / its not a tag and is part of the url
60 if (tag.indexOf('/') === -1) {
61 return {
62 repository: input.slice(0, separatorPos),
63 tag: tag
64 };
65 }
66
67 return {
68 repository: input
69 };
70};