toFirestoreValue()function
toFirestoreValue(value: unknown, caller: AnyCaller = toFirestoreValue): FirestoreValue
| Param | Type | |
|---|---|---|
value | unknown | The value to convert (null, boolean, string, finite number, array, or plain object). required |
caller | AnyCaller | Caller function used to attribute thrown errors. Defaults to toFirestoreValue |
| Return | |
|---|---|
FirestoreValue | The Firestore JSON value. |
| Throws | |
|---|---|
unknown | ValueError if the value cannot be represented (e.g. undefined, functions, non-finite numbers, class instances). |
Convert a data value to its Firestore REST API JSON representation.
- Safe integers become
integerValue(which the REST API encodes as a string), other finite numbers becomedoubleValue. - Arrays and plain objects convert recursively.
Examples
toFirestoreValue(123) // { integerValue: "123" }