Data Caster

Data Caster

  • Docs
  • GitHub

›Processing

General

  • Getting Started

Transformations

  • Basics
  • Phases

API reference

    Initialization

    • init
    • clone

    Rules

    • string
    • number
    • int
    • bool
    • date
    • object
    • array
    • stringArray
    • numberArray
    • intArray
    • boolArray
    • dateArray
    • objectArray
    • any

    Field manipulations

    • exclude
    • include
    • clearExcluded
    • ignoreExcluded

    Processing

    • adapt
    • adaptList
    • revert
    • revertList

adaptList

Adapts array of data from server in according to DataCaster instance rules.

Under the hood this method just iterates input collection and invokes for every item the adapt() method.

This method is NOT chainable: it produces an array of plane objects.

Signature

adaptList(rawData = [])

If rawData is not an Array instance the result will be an empty array: []

Example

import { DataCaster } from '@daminort/data-caster';

const users = [
  { id: '1', name: 'John Snow', is_active: '1' },
  { id: '2', name: 'Arya Stark', is_active: '0' },
];

const dc = new DataCaster()
  .int('id')
  .string('name')
  .bool('is_active');
    
// ...
// somewhere in codebase 
const adaptedUsers = dc.adaptList(users);
// adaptedUsers
[
  { id: 1, name: 'John Snow', isActive: true },
  { id: 2, name: 'Arya Stark', isActive: false },
]
← adaptrevert →
  • Signature
  • Example
Data Caster
Docs
Getting StartedBasicsAPI Reference
More
GitHubFacebook Open Source
Copyright © 2019 Demien