Skip to content

toSnapshot

Get a snapshot of a Dinero object.

Snapshots are plain JavaScript objects, suited for transport and storage. They're also useful when you need to retrieve raw data from a Dinero object.

Parameters

NameTypeDescriptionRequired
dineroObjectDinero<TAmount>The Dinero object to snapshot.Yes

Code examples

Get a snapshot of an object

js
import { dinero, toSnapshot } from 'dinero.js';
import { USD } from '@dinero.js/currencies';

const d = dinero({ amount: 500, currency: USD });

toSnapshot(d);

// {
//   amount: 500,
//   currency: {
//     code: 'USD',
//     base: 10,
//     exponent: 2,
//   },
//   scale: 2,
// }

Released under the MIT License.