@macrof/shared
Version:
React MicroFrontend Shared, Typescript, Webpack 5, ModuleFederation
39 lines (38 loc) • 1.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.includedPath = exports.plainToNew = exports.isEmptyObject = exports.isFilledObject = void 0;
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
const isObjectLike_1 = __importDefault(require("lodash/isObjectLike"));
const isFilledObject = (value) => (0, isPlainObject_1.default)(value) && Object.keys(value).length > 0;
exports.isFilledObject = isFilledObject;
const isEmptyObject = (value) => (0, isPlainObject_1.default)(value) && Object.keys(value).length === 0;
exports.isEmptyObject = isEmptyObject;
const plainToNew = (TypeName, value, ...args) => {
if (value instanceof TypeName || isEmptyObject(value) || (Array.isArray(value) && value.length === 0)) {
return value;
}
if (Array.isArray(value) && value[0] instanceof TypeName) {
return value.map((x) => x);
}
if (Array.isArray(value) && (0, isPlainObject_1.default)(value[0])) {
return value.map((x) => new TypeName(x, ...args));
}
if (isFilledObject(value)) {
return new TypeName(value, ...args);
}
if (Array.isArray(value) && (0, isObjectLike_1.default)(value[0])) {
return value.map((x) => new TypeName(x, ...args));
}
return undefined;
};
exports.plainToNew = plainToNew;
const includedPath = (first, second) => {
if (first && second && first.length > 1 && second.length > 1) {
return first.includes(second) || second.includes(first);
}
return false;
};
exports.includedPath = includedPath;