@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
80 lines • 1.72 kB
JavaScript
/**
* @module Utilities
*/
/**
* @internal
*/
export function isFactoryFn(factory) {
return typeof factory === "function";
}
/**
* @internal
*/
export function isFactoryObject(factory) {
return (typeof factory === "object" &&
factory !== null &&
typeof factory["use"] === "function");
}
/**
* @internal
*/
export function isFactory(factoryable) {
return isFactoryFn(factoryable) || isFactoryObject(factoryable);
}
/**
* @internal
*/
export function isAsyncFactoryFn(factory) {
return typeof factory === "function";
}
/**
* @internal
*/
export function isAsyncFactoryObject(factory) {
return (typeof factory === "object" &&
factory !== null &&
typeof factory["use"] === "function");
}
/**
* @internal
*/
export function isAsyncFactory(factoryable) {
return isAsyncFactoryFn(factoryable) || isAsyncFactoryObject(factoryable);
}
/**
* @internal
*/
export function resolveFactory(factory) {
if (isFactoryObject(factory)) {
return (value) => factory.use(value);
}
return factory;
}
/**
* @internal
*/
export function resolveAsyncFactory(factory) {
if (isAsyncFactoryObject(factory)) {
return (value) => factory.use(value);
}
return (value) => factory(value);
}
/**
* @internal
*/
export function resolveFactoryable(factoryable, input) {
if (isFactory(factoryable)) {
return resolveFactory(factoryable)(input);
}
return factoryable;
}
/**
* @internal
*/
export async function resolveAsyncFactoryable(factoryable, input) {
if (isAsyncFactory(factoryable)) {
return await resolveAsyncFactory(factoryable)(input);
}
return factoryable;
}
//# sourceMappingURL=factory.js.map