🛠️ hexo scripts

This commit is contained in:
shenyu
2021-05-24 11:28:56 +08:00
parent 1c857a0c5f
commit 0163b6bfe5
5 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
'use strict';
const joinPath = function(base, relative) {
if (relative && /^https*:\/\//.test(relative)) {
return relative;
}
return relative
? base.replace(/\/+$/, '') + '/' + relative.replace(/^\/+/, '')
: base;
};
module.exports = joinPath;

31
scripts/utils/object.js Normal file
View File

@@ -0,0 +1,31 @@
'use strict';
const isObject = (obj) => {
return obj && typeof obj === 'object' && !Array.isArray(obj);
};
const isNotEmptyObject = (obj) => {
return obj && typeof obj === 'object' && Object.getOwnPropertyNames(obj).length !== 0;
};
const merge = (target, ...sources) => {
for (const source of sources) {
for (const key in source) {
if (!Object.prototype.hasOwnProperty.call(source, key)) {
continue;
}
if (isObject(target[key]) && isObject(source[key])) {
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
}
return target;
};
module.exports = {
isObject,
isNotEmptyObject,
merge
};