object-shape-tester
Version:
Test object properties and value types.
31 lines (30 loc) • 777 B
JavaScript
import { check } from '@augment-vir/assert';
import { isShapeSpecifierKey } from './shape-keys.js';
/**
* A key used to identify custom specifier instances.
*
* @category Internal
*/
export const customSpecifierKey = '__vir__custom__specifier__key__do__not__use__in__actual__objects';
/**
* Checks if the given input is a custom specifier.
*
* @category Internal
*/
export function isCustomSpecifier(input) {
return check.hasKey(input, customSpecifierKey);
}
/**
* Use this to define a custom shape.
*
* @category Shape Part
*/
export function customShape({ customName, defaultValue, checker, }) {
return {
customName,
checker: checker,
defaultValue,
[customSpecifierKey]: true,
[isShapeSpecifierKey]: true,
};
}