Current version 22.0.0

Ensure

To convert properties to be used with Angular's @Input property decorator in a component.

Boolean

import { ensureBool } from '@trademe/tangram';

Transforms the input into a boolean.
Will throw an error if this fails.

Code

@Input({transform: (v: any) => ensureBool('exampleProperty', v)}) public exampleProperty: boolean;
Parameters

ensureBool(key, value, defaultValue)

ArgumentTypeDescription
keystring Name of the property, or key, that's being assigned to. Used for observability.
valueanyValue to be transformed.
defaultValue?booleanOptional: Default value that is returned if value is null or undefined.

Number

import { ensureNumber } from '@trademe/tangram';

Transforms the input into a number.
Will throw an error if this fails.

Code

@Input({transform: (v: any) => ensureNumber('exampleProperty', v)}) public exampleProperty: number;

ensureNumber(key, value, defaultValue)

Parameters
ArgumentTypeDescription
keystring Name of the property, or key, that's being assigned to. Used for observability.
valueanyValue to be transformed.
defaultValue?booleanOptional: Default value that is returned if value is null or undefined.

Mutually Exclusive

import { ensureMutuallyExclusive } from '@trademe/tangram';

Ensures that only one of the two provided properties are being assigned a value.
Will throw an error if this fails.

Code

@Input({transform: function(v: any) => ensureMutuallyExclusive('exampleProperty', this, 'otherProperty', v)}) public exampleProperty: any;
Parameters

ensureMutuallyExclusive(key, component, mutuallyExclusiveKey, value)

ArgumentTypeDescription
keystring Name of the property, or key, that's being assigned to. Used for observability.
componentRecord<string, any> The component this transform function is operating on. Can be retrieved using the `this` keyword in the transform block.
mutuallyExclusiveKeystring Name of the property, or key, that cannot also be true while key is true.
valueanyValue to be transformed

Enum

import { ensureEnum } from '@trademe/tangram';

Transforms the input into the provided enum.
Will throw an error if this fails.

Code

@Input({transform: (v: any) => ensureEnum('exampleProperty', MyEnum, v)}) public exampleProperty: MyEnum;
Parameters

ensureEnum(key, targetEnum, value, defaultValue)

ArgumentTypeDescription
keystring Name of the property, or key, that's being assigned to. Used for observability.
targetEnum<T>Enum that the value must be a part of.
valueanyValue to be transformed.
defaultValue?booleanOptional: Default value that is returned if value is null or undefined.

Regexp

import { ensureRegex } from '@trademe/tangram';

Transforms the input into a regex.
Will attempt to parse non-string inputs into a regex, which may have surprising results.
Will throw an error if an invalid regex pattern is passed in (eg. '(()').

Code

@Input({transform: (v: any) => ensureRegex('exampleProperty', v)}) public exampleProperty: Regex;
Parameters

ensureRegex(key, value, defaultValue)

ArgumentTypeDescription
keystring Name of the property, or key, that's being assigned to. Used for observability.
valueanyValue to be transformed.
defaultValue?anyOptional: Default value that is returned if value is null or undefined.
Proudly made by © 2026 Trade Me Limited