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

revertList

An opposite operation to adaptList().

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

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

Signature

revertList(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);
const originUsers = dc.revertList(adaptedUsers);
// adaptedUsers
[
  { id: 1, name: 'John Snow', isActive: true },
  { id: 2, name: 'Arya Stark', isActive: false },
]

// originUsers
[
  { id: 1, name: 'John Snow', is_active: true },
  { id: 2, name: 'Arya Stark', is_active: false },
]
← revert
  • Signature
  • Example
Data Caster
Docs
Getting StartedBasicsAPI Reference
More
GitHubFacebook Open Source
Copyright © 2019 Demien