UNPKG

cooky-cutter

Version:

Object factories for testing in TypeScript

33 lines (32 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isArrayFactoryFunction = exports.isFactoryFunction = exports.isDerivedFunction = exports.isAttributeFunction = void 0; const derive_1 = require("./derive"); const define_1 = require("./define"); const array_1 = require("./array"); // Determine if the function is an internal derive function based on properties // defined on the function. function isDerivedFunction(fn) { return fn && fn.__cooky_cutter === derive_1.DERIVE_FUNCTION_KEY; } exports.isDerivedFunction = isDerivedFunction; // Determine if the function is an internal factory function based on properties // defined on the function. function isFactoryFunction(fn) { return fn && fn.__cooky_cutter === define_1.FACTORY_FUNCTION_KEY; } exports.isFactoryFunction = isFactoryFunction; // Determine if the function is an internal array factory function based on // properties defined on the function. function isArrayFactoryFunction(fn) { return fn && fn.__cooky_cutter === array_1.ARRAY_FACTORY_KEY; } exports.isArrayFactoryFunction = isArrayFactoryFunction; // Determine if the function is an attribute function. Since this is end-user // defined there is not a great way to know for sure if it exactly matches // an attribute function, but this is a best guess. This should be used after // all other function type checks. function isAttributeFunction(fn) { return fn && {}.toString.call(fn) === "[object Function]"; } exports.isAttributeFunction = isAttributeFunction;