Creates a new FunctionShape instance.
The shape of the array of arguments.
The return value shape, or null
if unconstrained.
The shape of this
argument, or null
if unconstrained.
Optional
options: IssueOptions | MessageThe issue options or the issue message.
Protected
_optionsThe type issue options or the type issue message.
Protected
_parseParsing options that are used by a wrapper.
The dictionary of shape annotations.
Readonly
argsThe shape of the array of arguments.
Readonly
inputsThe array of unique input types and values that are accepted by the shape.
Readonly
istrue
if the shape allows only Shape.parseAsync and throws an error if Shape.parse is called, or
false
if the shape can be used in both sync and async contexts.
true
if input functions are wrapped during parsing to ensure runtime signature type-safety, or false
otherwise.
The array of operations that are applied to the shape output.
Readonly
returnThe return value shape, or null
if unconstrained.
Readonly
thisThe shape of this
value, or null
if unconstrained.
Protected
_applySynchronously parses the input.
The shape input to parse.
Parsing options.
The globally unique number that identifies the parsing process.
null
if input matches the output, Ok that wraps the output, or an array of captured issues.
Protected
_applyAsynchronously parses the input.
The shape input to parse.
Parsing options.
null
if input matches the output, Ok that wraps the output, or an array of captured issues.
Protected
_applyThe callback that applies Shape.operations to the shape output value.
This method returns a promise if there are async Shape.operations.
If the shape overrides only Shape._apply and doesn't override Shape._applyAsync then it's only safe to call this method as the last statement in Shape._apply. Otherwise, it may return an unexpected promise.
If the shape overrides both Shape._apply and Shape._applyAsync then this method would always synchronously return a Result inside Shape._apply.
Protected
_cloneProtected
_getProtected
_isAdds an asynchronous operation to the shape.
The callback that asynchronously applies an operation to the shape output value.
Optional
options: ParameterizedOperationOptions<Param>The operation options.
The clone of the shape.
Adds an asynchronous operation to the shape.
The callback that asynchronously applies an operation to the shape output value.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Adds a synchronous operation to the shape.
The callback that synchronously applies an operation to the shape output value.
Optional
options: ParameterizedOperationOptions<Param>The operation options.
The clone of the shape.
Adds a synchronous operation to the shape.
The callback that synchronously applies an operation to the shape output value.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Allows an input value, so it is passed directly to the output.
The allowed value.
The allowed value.
Adds a synchronous operation that alters the output value without changing its type.
If you want to change the base type, consider using Shape.convert.
The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.
The operation options.
The clone of the shape.
Adds a synchronous operation that alters the output value without changing its type.
If you want to change the base type, consider using Shape.convert.
The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Adds an asynchronous operation that alters the output value without changing its type.
If you want to change the base type, consider using Shape.convertAsync.
The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.
The operation options.
The clone of the shape.
Adds an asynchronous operation that alters the output value without changing its type.
If you want to change the base type, consider using Shape.convertAsync.
The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Returns a sub-shape that describes a value associated with the given property name, or null
if there's no such
sub-shape.
The key for which the sub-shape must be retrieved.
The sub-shape or null
if there's no such key in the shape.
Returns a shape that adds a brand to the output type.
A shape with the branded output type.
Returns undefined
if parsing fails.
Returns the fallback value if parsing fails.
The fallback value.
The value or a callback that returns a value that is returned if parsing has failed. A callback receives an input value, an array of raised issues, and parsing options.
Adds a synchronous operation that checks that the shape output satisfies a requirement.
The callback must return null
or undefined
if value is valid, or an issue or an array of issues
if value is invalid. If a callback returns an empty array, it is considered that no issues have occurred.
The callback that checks that a value satisfies a requirement and returns issues if it doesn't.
The operation options.
The clone of the shape.
Adds a synchronous operation that checks that the shape output satisfies a requirement.
The callback must return null
or undefined
if value is valid, or an issue or an array of issues
if value is invalid. If a callback returns an empty array, it is considered that no issues have occurred.
The callback that checks that a value satisfies a requirement and returns issues if it doesn't.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Adds an asynchronous operation that checks that the shape output satisfies a requirement.
The callback must return a promise that is resolved with null
or undefined
if value is valid, or an
issue or an array of issues if value is invalid. If promise resolves with an empty array, it is
considered that no issues have occurred.
The callback that checks that a value satisfies a requirement and returns issues if it doesn't.
The operation options.
The clone of the shape.
Adds an asynchronous operation that checks that the shape output satisfies a requirement.
The callback must return a promise that is resolved with null
or undefined
if value is valid, or an
issue or an array of issues if value is invalid. If promise resolves with an empty array, it is
considered that no issues have occurred.
The callback that checks that a value satisfies a requirement and returns issues if it doesn't.
Optional
options: OperationOptionsThe operation options.
The clone of the shape.
Synchronously converts the output value of the shape.
If you want to don't want to change the base type, consider using Shape.alter.
The callback that converts the input value. Throw a ValidationError to notify that the conversion cannot be successfully completed.
The ConvertShape instance.
Asynchronously converts the output value of the shape.
If you want to don't want to change the base type, consider using Shape.alterAsync.
The callback that converts the input value asynchronously. The returned promise can be rejected with a ValidationError to notify that the conversion cannot be successfully completed.
The ConvertShape instance.
Excludes value from both input and output.
The denied value.
The excluded value.
Optional
options: IssueOptions | MessageThe issue options or the issue message.
Creates a function that ensures that fn
receives arguments and this
value that conform the argsShape
and the thisShape respectively, and synchronously returns the value that conforms the returnShape.
The function to which signature must be ensured.
The underlying function.
Optional
options: ParseOptionsParsing options. By default, options provided to the strict method are used.
The wrapper function.
Creates a function that ensures that fn
receives arguments and this
value that conform the argsShape
and the thisShape respectively, and asynchronously returns the value that conforms the returnShape.
Use this method if some shapes that describe the function signature are async.
The function to which signature must be ensured.
The underlying function.
Optional
options: ParseOptionsParsing options. By default, options provided to the strict method are used.
The wrapper function.
Checks that the input doesn't match the shape.
The shape to which the output must not conform.
The shape to which the output must not conform.
Optional
options: IssueOptions | MessageThe issue options or the issue message.
Prevents an input and output from being undefined
.
Optional
options: IssueOptions | MessageThe issue options or the issue message.
Checks that the input doesn't match the shape.
This method works exactly as Shape.exclude at runtime, but it doesn't perform the exclusion on the type level.
The shape to which the output must not conform.
The shape to which the output must not conform.
Optional
options: IssueOptions | MessageThe issue options or the issue message.
Replaces null
input value with an null
output value.
Replaces null
input value with a default output value.
The value that is used as the replacement for null
.
The value that should be used if an input value is null
.
Passes null
and undefined
input values directly to the output without parsing.
Replaces null
and undefined
input value with a default output value.
The value that is used as the replacement for undefined
and null
.
Optional
defaultValue: DefaultValueThe value that should be used if an input value is undefined
or null
.
Replaces undefined
input value with an undefined
output value.
Replaces undefined
input value with a default output value.
The value that is used as the replacement for undefined
.
The value that should be used if an input value is undefined
.
Synchronously parses the value.
The value to parse.
Optional
options: ParseOptionsParsing options.
The value that conforms the output type of the shape.
Error if the shape doesn't support the sync parsing, see Shape.isAsync.
ValidationError if any issues occur during parsing.
Asynchronously parses the value.
The value to parse.
Optional
options: ParseOptionsParsing options.
The promise that resolves with the value that conforms the output type of the shape, or rejects with a ValidationError if any issues occur during parsing.
Synchronously parses the value and returns undefined
if parsing fails.
The value to parse.
The value that conforms the output type of the shape.
Error if the shape doesn't support the sync parsing, see Shape.isAsync.
Synchronously parses the value and returns the default value if parsing fails.
The value to parse.
The default value that is returned if parsing fails.
Optional
options: ParseOptionsParsing options.
The value that conforms the output type of the shape.
Error if the shape doesn't support the sync parsing, see Shape.isAsync.
Asynchronously parses the value and returns undefined
value if parsing fails.
The value to parse.
The value that conforms the output type of the shape.
Asynchronously parses the value and returns the default value if parsing fails.
The value to parse.
The default value that is returned if parsing fails.
Optional
options: ParseOptionsParsing options.
The value that conforms the output type of the shape.
Adds a synchronous operation that refines the shape output type with the narrowing predicate.
The narrowed output value.
The param that is passed to the operation when it is applied.
The predicate that returns true
if the value conforms the required type, or false
otherwise.
The operation options or the issue message.
The shape with the narrowed output.
Adds a synchronous operation that refines the shape output type with the narrowing predicate.
The narrowed output value.
The predicate that returns true
if the value conforms the required type, or false
otherwise.
Optional
options: Message | RefineOptionsThe operation options or the issue message.
The shape with the narrowed output.
Adds a synchronous operation that checks that the output value conforms the predicate.
The predicate that returns truthy result if the value is valid, or returns falsy result otherwise.
Optional
options: Message | ParameterizedRefineOptions<Param>The operation options or the issue message.
The clone of the shape.
Adds a synchronous operation that checks that the output value conforms the predicate.
The predicate that returns truthy result if the value is valid, or returns falsy result otherwise.
Optional
options: Message | RefineOptionsThe operation options or the issue message.
The clone of the shape.
Adds an asynchronous operation that checks that the output value conforms the predicate.
The predicate that returns a promise that resolves with a truthy result if the value is valid, or a falsy result otherwise.
Optional
options: Message | ParameterizedRefineOptions<Param>The operation options or the issue message.
The clone of the shape.
Adds an asynchronous operation that checks that the output value conforms the predicate.
The predicate that returns a promise that resolves with a truthy result if the value is valid, or a falsy result otherwise.
Optional
options: Message | RefineOptionsThe operation options or the issue message.
The clone of the shape.
Replaces an input value with an output value.
The input value to replace.
The output value that is returned if an inputValue
is received.
Constrains the function return value with the given shape.
The return value shape.
The return value shape, or null
if unconstrained.
The new function shape.
Enables input function wrapping during parsing to ensure runtime signature type-safety. Wrapper ensures that input
function receives arguments and this
values that conform the argsShape and thisShape respectively,
and returns the value that conforms returnShape.
Optional
options: ParseOptionsOptions that are used by the wrapper. If omitted then default options are applied: no early-return, no type coercion.
The new function shape.
Constrains the type of this
inside the function.
The shape of this
argument.
The shape of this
argument, or null
if unconstrained.
The new function shape.
Pipes the output of this shape to the input of another shape.
The output value.
The shape that validates the output if this shape.
The value to parse.
Optional
options: ParseOptionsParsing options.
The Ok instance if parsing has succeeded or Err if parsing has failed.
Error if the shape doesn't support the sync parsing, see Shape.isAsync.
The value to parse.
Optional
options: ParseOptionsParsing options.
The Ok instance if parsing has succeeded or Err if parsing has failed.
true
if some shapes that describe the function signature are async, or false
otherwise.
The shape of a function.