# @odata2ts/converter-v2-to-v4

> A set of odata2ts compatible converters to convert certain OData V2 types to their V4 analog

Latest version **0.5.8** (published 2026-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @odata2ts/converter-v2-to-v4
pnpm add @odata2ts/converter-v2-to-v4
yarn add @odata2ts/converter-v2-to-v4
bun add @odata2ts/converter-v2-to-v4
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.8 |
| Published | 2026-08-06 |
| First published | 2022-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 39.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | texttechne |
| Maintainers | texttechne |
| Keywords | odata2ts, odata, odata v2, odata v4, converter, datetime, datetimeoffset, time, typescript, ts, javascript, js, types, data types |

## Links

- npm: https://www.npmjs.com/package/@odata2ts/converter-v2-to-v4
- Repository: git@github.com:odata2ts/converter.git
- npm.io page: https://npm.io/package/@odata2ts/converter-v2-to-v4

## Dependencies (1)

- [@odata2ts/converter-api](https://npm.io/package/@odata2ts/converter-api.md) ^0.3.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.5.8 (latest) — 2026-08-06
- 0.5.7 — 2025-02-08
- 0.5.6 — 2025-02-08
- 0.5.4 — 2024-12-18
- 0.5.3 — 2024-08-25
- 0.5.2 — 2024-08-24
- 0.5.1 — 2024-08-14
- 0.5.0 — 2024-08-13
- 0.4.0 — 2023-08-30
- 0.3.1 — 2023-07-21
- 0.3.0 — 2023-07-21
- 0.2.1 — 2023-05-23
- 0.2.0 — 2023-05-22
- 0.1.4 — 2023-04-13
- 0.1.3 — 2023-04-08
- … 3 more at https://npm.io/package/@odata2ts/converter-v2-to-v4/versions

## README

[![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/converter-v2-to-v4?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/converter-v2-to-v4)

# V2-to-V4 Converters

A set of [odata2ts](https://github.com/odata2ts/odata2ts) compatible converters to convert certain OData V2 types to their V4 analog.
Thus, other converters only need to take care of the V4 data models.

## Conversions

| OData V2 Type  | Result Type           | Converter Id                                       | Description                                                                                            |
| -------------- | --------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `Edm.DateTime` | `Edm.DateTimeOffset`  | dateTimeToDateTimeOffsetConverter                  | Converts "/Date(123...)/" to ISO8601 "2022-02-22T12:00:00Z"; offsets are supported "/Date(123..+120)/" |
| `Edm.Byte`     | `number`              | stringToNumberConverter                            |                                                                                                        |
| `Edm.SByte`    | `number`              | stringToNumberConverter                            |                                                                                                        |
| `Edm.Single`   | `number`              | stringToNumberConverter                            |                                                                                                        |
| `Edm.Double`   | `number`              | stringToNumberConverter                            |                                                                                                        |
| `Edm.Int64`    | `number`<br/>`string` | stringToNumberConverter<br/>bigNumberNoopConverter | By default, converted to `number`, with the help of the noop converter `string`                        |
| `Edm.Decimal`  | `number`<br/>`string` | stringToNumberConverter<br/>bigNumberNoopConverter | By default, converted to `number`, with the help of the noop converter `string`                        |
| `Edm.Time`     | `Edm.TimeOfDay`       | timeToTimeOfDayConverter                           | Converts duration format to time format, e.g. `PT12H15M` to `12:15:00`                                 |
| `Edm.Time`     | `Edm.Duration`        | timeToDurationConverter                            | Relabels `Edm.Time` to `Edm.Duration` (no conversion required); not a default converter                |

### Note on Big Numbers

`Edm.Int64` & `Edm.Decimal` get converted to the `number` type as V4 does it.
However, please note that those numbers potentially don't fit into JS' number type,
which might result in precision loss.

In order to prevent such precision loss, you could use additional converters **after**
this converter, e.g. `int64ToBigIntConverter` from the common converter package.

Alternatively, you can use the `bigNumberNoopConverter` from this package to keep those
types as `string`. This would like this in the `odata2ts` configuration:

```ts
{
  converters: [
    {
      module: "@odata2ts/converter-v2-to-v4",
      use: [
        "stringToNumberConverter",
        "bigNumberNoopConverter",
        "dateTimeToDateTimeOffsetConverter",
        "timeToTimeOfDayConverter",
      ],
    },
  ];
}
```

## Installation

```
npm install --save @odata2ts/converter-v2-to-v4
```

## Documentation

[V2-to-V4-Converter Documentation](https://odata2ts.github.io/docs/generator/converters/v2-to-v4-converter)

Main Documentation of odata2ts: [https://odata2ts.github.io/](https://odata2ts.github.io/)

## Support, Feedback, Contributing

This project is open to feature requests, suggestions, bug reports, usage questions etc.
via [GitHub issues](https://github.com/odata2ts/converter/issues).

Contributions and feedback are encouraged and always welcome.

See the [contribution guidelines](https://github.com/odata2ts/converter/blob/main/CONTRIBUTING.md) for further information.

## Spirit

This project has been created and is maintained in the following spirit:

- adhere to the **OData specification** as much as possible
  - support any OData service implementation which conforms to the spec
  - allow to work around faulty implementations if possible
- stability matters
  - exercise Test Driven Development
  - bomb the place with unit tests (code coverage > 95%)
  - ensure that assumptions & understanding are correct by creating integration tests

## License

MIT - see [License](./LICENSE).

---
_Source: https://npm.io/package/@odata2ts/converter-v2-to-v4 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
