@methodus/server
Version:
Server components for @methodus workflow
68 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class fp {
static maybe(object) {
if (!object) {
return {};
}
return object;
}
static unique(myArray) {
return [...new Set(myArray)];
}
static maybeProto(object) {
if (!object || object.methodus) {
return object;
}
let proto = object.prototype;
if (proto && (proto.length === 0 || Object.keys(proto).length === 0) && proto.constructor) {
proto = proto.constructor;
}
if (!proto) {
proto = object.__proto__;
}
return proto;
}
static maybeMethodus(object) {
if (!object) {
return null;
}
if (object.methodus) {
return object.methodus;
}
const proto = object.prototype;
if (proto && proto.constructor && proto.constructor.methodus) {
return proto.constructor.methodus;
}
if (!proto && object.__proto__ && object.__proto__.methodus) {
return object.__proto__.methodus;
}
return proto.methodus;
}
static maybeEach(object, callback) {
if (object.forEach) {
object.forEach((item) => {
callback(item);
});
}
}
static maybeJson(object) {
if (!object) {
return {};
}
try {
return JSON.parse(object);
}
catch (error) {
return {};
}
}
static maybeString(object) {
if (!object) {
return '';
}
return object;
}
}
exports.fp = fp;
//# sourceMappingURL=fp.js.map