UNPKG

@toreda/strong-types

Version:

Better TypeScript code in fewer lines.

25 lines (24 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.strongMake = void 0; const rules_1 = require("../rules"); const type_1 = require("../create/type"); const value_1 = require("../initial/value"); /** * Create Strong object using provided arguments. Should generally be called * by helper functions or factories which create the desired type and pass in * type rules consistently. * @param fallback Value returned when type's current `value` is null. * @param initial (Optional) Initial value for type. When not provided, type's * initial value is `fallback` instead. When reset is called, value * is automatically set to initial if it was provided, or fallback if not. * @param rules Automatic type validation rules applied to any value used with `set`. * @returns * * @category Core */ function strongMake(fallback, initial, rules) { const rulesValue = rules instanceof rules_1.Rules ? rules : new rules_1.Rules(); return (0, type_1.createType)(fallback, (0, value_1.initialValue)(initial), rulesValue, 'StrongType'); } exports.strongMake = strongMake;