universal-webpack
Version:
Isomorphic Webpack
135 lines (105 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.is_object = is_object;
exports.extend = extend;
exports.merge = merge;
exports.clone = clone;
exports.starts_with = starts_with;
exports.ends_with = ends_with;
exports.exists = void 0;
// // if the variable is defined
var exists = function exists(what) {
return typeof what !== 'undefined';
}; // used for JSON object type checking
exports.exists = exists;
var object_constructor = {}.constructor; // detects a JSON object
function is_object(object) {
return exists(object) && object !== null && object.constructor === object_constructor;
} // extends the first object with
/* istanbul ignore next: some weird transpiled code, not testable */
function extend() {
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
objects[_key] = arguments[_key];
}
objects = objects.filter(function (x) {
return exists(x);
});
if (objects.length === 0) {
return;
}
if (objects.length === 1) {
return objects[0];
}
var to = objects[0];
var from = objects[1];
if (objects.length > 2) {
var last = objects.pop();
var intermediary_result = extend.apply(this, objects);
return extend(intermediary_result, last);
}
for (var _i = 0, _Object$keys = Object.keys(from); _i < _Object$keys.length; _i++) {
var key = _Object$keys[_i];
if (is_object(from[key])) {
if (!is_object(to[key])) {
to[key] = {};
}
extend(to[key], from[key]);
} else if (Array.isArray(from[key])) {
if (!Array.isArray(to[key])) {
to[key] = [];
}
to[key] = to[key].concat(clone(from[key]));
} else {
to[key] = from[key];
}
}
return to;
}
function merge() {
var parameters = Array.prototype.slice.call(arguments, 0);
parameters.unshift({});
return extend.apply(this, parameters);
}
function clone(object) {
if (is_object(object)) {
return merge({}, object);
} else if (Array.isArray(object)) {
return object.map(function (x) {
return clone(x);
});
} else {
return object;
}
}
function starts_with(string, substring) {
var j = substring.length;
if (j > string.length) {
return false;
}
while (j > 0) {
j--;
if (string[j] !== substring[j]) {
return false;
}
}
return true;
}
function ends_with(string, substring) {
var i = string.length;
var j = substring.length;
if (j > i) {
return false;
}
while (j > 0) {
i--;
j--;
if (string[i] !== substring[j]) {
return false;
}
}
return true; // const index = string.lastIndexOf(substring)
// return index >= 0 && index === string.length - substring.length
}
//# sourceMappingURL=helpers.js.map