58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.staticImplements = staticImplements;
|
|
exports.isPlainObject = isPlainObject;
|
|
exports.isFunction = isFunction;
|
|
exports.isIterable = isIterable;
|
|
exports.isString = isString;
|
|
exports.isNumber = isNumber;
|
|
exports.orElse = orElse;
|
|
exports.ifNull = ifNull;
|
|
exports.mixin = mixin;
|
|
exports.pipe = pipe;
|
|
function staticImplements() {
|
|
return (constructor) => { constructor; };
|
|
}
|
|
function isPlainObject(value) {
|
|
return Object.getPrototypeOf(value) === Object.prototype;
|
|
}
|
|
function isFunction(value) {
|
|
return value != null && typeof value === 'function';
|
|
}
|
|
function isIterable(value) {
|
|
return isFunction(value[Symbol.iterator]);
|
|
}
|
|
function isString(value) {
|
|
return typeof value === 'string';
|
|
}
|
|
function isNumber(value) {
|
|
return !isNaN(value);
|
|
}
|
|
function orElse(thisArg, a, b) {
|
|
return function (...args) {
|
|
const fn = a != null ? a : b;
|
|
return fn.apply(thisArg, args);
|
|
};
|
|
}
|
|
function ifNull(thisArg, b, ...args) {
|
|
return function (a) {
|
|
return orElse(thisArg, a, b).apply(thisArg, args);
|
|
};
|
|
}
|
|
function applyMixins(derivedCtor, constructors) {
|
|
constructors.forEach((baseCtor) => {
|
|
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
|
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
Object.create(null));
|
|
});
|
|
});
|
|
}
|
|
function mixin(impl) {
|
|
return function (constructor) {
|
|
applyMixins(constructor, [impl]);
|
|
return constructor;
|
|
};
|
|
}
|
|
function pipe(arg, firstFn, ...fns) {
|
|
return fns.reduce((acc, fn) => fn(acc), firstFn(arg));
|
|
}
|