# rawTransform

> This document is the Markdown version of [valibot.dev/api/rawTransform/](https://valibot.dev/api/rawTransform/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a raw transformation action.

```ts
const Action = v.rawTransform<TInput, TOutput>(action);
```

## Generics

- `TInput` `extends any`
- `TOutput` `extends any`

## Parameters

- `action` `(context: RawTransformContext<TInput>) => TOutput`

### Explanation

With `rawTransform` you can freely transform and validate the input with a custom `action` and add issues if necessary.

## Returns

- `Action` `RawTransformAction<TInput, TOutput>`

## Examples

The following examples show how `rawTransform` can be used.

### Calculate game result

Schema that calculates the total score of a game based on the scores and a multiplier.

> This `rawTransform` validation action adds an issue for points that exceed a certain maximum and forwards it via `path` to the appropriate nested score.

```ts
const GameResultSchema = v.pipe(
  v.object({
    scores: v.array(v.pipe(v.number(), v.integer())),
    multiplier: v.number(),
  }),
  v.rawTransform(({ dataset, addIssue, NEVER }) => {
    // Create total variable
    let total = 0;

    // Iterate over scores and check points
    for (let index = 0; index < dataset.value.scores.length; index++) {
      // Calculate points by multiplying score with multiplier
      const score = dataset.value.scores[index];
      const points = score * dataset.value.multiplier;

      // Add issue if points exceed maximum of 1,000 points
      if (points > 1_000) {
        addIssue({
          message:
            'The score exceeds the maximum allowed value of 1,000 points.',
          path: [
            {
              type: 'object',
              origin: 'value',
              input: dataset.value,
              key: 'scores',
              value: dataset.value.scores,
            },
            {
              type: 'array',
              origin: 'value',
              input: dataset.value.scores,
              key: index,
              value: score,
            },
          ],
        });

        // Abort transformation
        return NEVER;
      }

      // Add points to total
      total += points;
    }

    // Add calculated total to dataset
    return { ...dataset.value, total };
  })
);
```

## Related

The following APIs can be combined with `rawTransform`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md)

### Methods

[`forward`](/api/forward.md), [`pipe`](/api/pipe.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)
