@itrocks/data-to-object
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

npm version npm downloads GitHub issues discord

data-to-object

Transforms raw string-based data into a business object with type-safe values.

Installation

npm i @itrocks/data-to-object

Usage

import { dataToObject } from '@itrocks/data-to-object'

class User {
  name!: string
  age!: number
}

const rawData = {
  name: 'John Doe',
  age: '30'
}

const user = new User()

await dataToObject(user, rawData)

console.log(user)
// Output: { name: 'John Doe', age: 30 }

dataToObject Function

Converts raw data (e.g., JSON, web forms) into a business object by applying type-appropriate transformations to each property.

Parameters

  • object (T extends object) – The target object where the transformed values will be assigned.
  • data (RecursiveStringObject) – The raw data source with string values.

Behavior

Example Use Cases

  • Processing web form inputs safely (e.g. @itrocks/save).
  • Mapping JSON API responses to strongly-typed objects.
  • Cleaning and sanitizing data before storage or further processing.

Dependents (1)

Package Sidebar

Install

npm i @itrocks/data-to-object

Homepage

it.rocks

Weekly Downloads

8

Version

0.0.3

License

ISC

Unpacked Size

5.19 kB

Total Files

5

Last publish

Collaborators

  • baptistepillot