Value library
Contents
Helper functions for creating typed Java values from JavaScript — used when storing geo-points, instants, references, and similar typed fields in nodes and content.
Usage
Add the following to your build.gradle file:
dependencies {
include xplibs.value
}
Add the import statement to your code:
import valueLib from '/lib/xp/value';
You are now ready to use the API.
Functions
binary
Creates a BinaryAttachment value from a name and a binary stream.
Parameters
binary() takes two positional arguments: name (string — the binary name) and stream (ByteSource — the binary stream).
Returns
object : (BinaryAttachment)
geoPoint
Creates a GeoPoint value from numeric coordinates.
Parameters
geoPoint() takes two positional arguments: lat (number — latitude) and lon (number — longitude).
Returns
object : (GeoPoint)
geoPointString
Creates a GeoPoint value from a comma-separated latitude and longitude string.
Parameters
geoPointString() takes one positional argument: value (string — comma-separated latitude and longitude, e.g. '59.9139,10.7522').
Returns
object : (GeoPoint)
instant
Creates an Instant value from an ISO-8601 string or a Date object.
Parameters
instant() takes one positional argument: value (string | Date — an ISO-8601-formatted instant such as '2011-12-03T10:15:30Z', or a JavaScript Date).
Returns
object : (Instant)
localDate
Creates a LocalDate value from an ISO local date string or a Date object.
Parameters
localDate() takes one positional argument: value (string | Date — an ISO local date such as '2011-12-03', or a JavaScript Date).
Returns
object : (LocalDate)
localDateTime
Creates a LocalDateTime value from a local date-time string or a Date object.
Parameters
localDateTime() takes one positional argument: value (string | Date — a local date-time string such as '2007-12-03T10:15:30', or a JavaScript Date).
Returns
object : (LocalDateTime)
Type Definitions
GeoPoint
A typed geo-point value. Returned by geoPoint() and geoPointString().
Methods
| Name | Type | Description |
|---|---|---|
|
|
number |
The latitude component. |
|
|
number |
The longitude component. |
|
|
string |
Serialized form — |
Instant
A typed instant (point in time) value. Returned by instant().
Methods
| Name | Type | Description |
|---|---|---|
|
|
number |
Seconds since the Unix epoch. |
|
|
number |
Nanoseconds adjustment within the current second. |
|
|
number |
Milliseconds since the Unix epoch. |
Reference
A typed node reference value. Returned by reference().
Methods
| Name | Type | Description |
|---|---|---|
|
|
string |
The referenced node ID. |
|
|
string |
String form of the node ID. |
LocalDateTime
A typed local date-time value (no time-zone). Returned by localDateTime().
Methods
| Name | Type | Description |
|---|---|---|
|
|
number |
The year. |
|
|
number |
Month as a number (1–12). |
|
|
string |
Month as a string constant (e.g. |
|
|
number |
Day of the month (1–31). |
|
|
string |
Day of the week as a string constant (e.g. |
|
|
number |
Hour of day (0–23). |
|
|
number |
Minute of hour (0–59). |
|
|
number |
Second of minute (0–59). |
|
|
number |
Nanosecond of second. |
LocalDate
A typed local date value (no time, no time-zone). Returned by localDate().
Methods
| Name | Type | Description |
|---|---|---|
|
|
number |
The year. |
|
|
number |
Month as a number (1–12). |
|
|
string |
Month as a string constant (e.g. |
|
|
number |
Day of the month (1–31). |
|
|
number |
Day of the year (1–366). |
|
|
string |
Day of the week as a string constant (e.g. |
|
|
boolean |
Whether the year is a leap year. |
LocalTime
A typed local time value (no date, no time-zone). Returned by localTime().
Methods
| Name | Type | Description |
|---|---|---|
|
|
number |
Hour of day (0–23). |
|
|
number |
Minute of hour (0–59). |
|
|
number |
Second of minute (0–59). |
|
|
number |
Nanosecond of second. |
BinaryAttachment
A typed binary attachment value wrapping a name reference and a stream. Returned by binary().
Methods
| Name | Type | Description |
|---|---|---|
|
|
object |
A |
|
|
The underlying binary stream. |