Data Caster

Data Caster

  • Docs
  • GitHub

›Initialization

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

init

Makes initialization of DataCaster instance.

This method is chainable.

Signature

init(options = {})

options is an object that can be omitted and thus it will use options by default:

const defaultOptions = {
  forceCamelCase: true,  // transform object's properties into 'camelCase'-notation
  ignoreExcluded: false, // allowing temporarily switch off and on using excluded fields
};

If you don't need to replace default options you can omit using this method at all.

Example

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

const dc = new DataCaster()
  .init({
    forceCamelCase: false,
   })
  .int('id')
  .string('user_name');
    
const result = dc.adapt(serverObject);
// before
{
  id: 1,
  user_name: 'John Snow',
}

// after
{
  id: 1,
  user_name: 'John Snow',
}
← Phasesclone →
  • Signature
  • Example
Data Caster
Docs
Getting StartedBasicsAPI Reference
More
GitHubFacebook Open Source
Copyright © 2019 Demien