new DiaryFitbit(file, serialiseropt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
file |
Object | file contents | |
serialiser |
function |
<optional> |
function to serialise output |
- Source:
Example
let diary = new_sleep_diary(contents_of_my_file));
console.log(diary.records);
-> [
{
"start" : 12345678,
"end" : 23456789,
"Start Time" : "2010-10-10 8:09PM",
"End Time" : "2010-10-11 7:08AM",
"Minutes Asleep" : "500",
"Minutes Awake" : "50",
"Number of Awakenings": "30",
"Time in Bed" : "500",
"Minutes REM Sleep" : "100",
"Minutes Light Sleep" : "300",
"Minutes Deep Sleep" : "100",
},
...
]
Extends
Members
"records" :Array
Individual records from the sleep diary
Type:
- Array
- Source:
(protected) "spreadsheet" :Spreadsheet
Spreadsheet manager
Type:
- Source:
serialiser :function
Serialise a value for output
Type:
- function
- Overrides:
- Source:
Methods
clone()
Create a deep copy of the current object
- Overrides:
- Source:
(protected) corrupt(file, message)
Indicates the file is a corrupt file in the specified format
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Object | file contents, or filename/contents pairs (for archive files) |
message |
string | optional error message |
- Overrides:
- Source:
(protected) invalid(file)
Indicates the file is not valid in our file format
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Object | file contents, or filename/contents pairs (for archive files) |
- Overrides:
- Source:
merge(other)
Merge another diary into this one
Parameters:
Name | Type | Description |
---|---|---|
other |
DiaryBase | diary to merge in |
- Overrides:
- Source:
Example
diary.merge(my_data);
(protected) serialise()
Serialise data for output
- Overrides:
- Source:
software_version() → {string}
Version ID for this package
- Overrides:
- Source:
Returns:
- Type
- string
timezones() → {Array.<string>}
Complete list of allowed timezones
- Overrides:
- Source:
Returns:
- Type
- Array.<string>
to(to_format) → {*}
Convert a value to some other format
Supported formats:
- url - contents serialised for inclusion in a URL
- json - contents serialised to JSON
- storage-line - contents serialised for inclusion in a newline-separated list of diaries
- Standard - Standard format
- (other formats) - the name of any other diary format
to_async() supports more formats and should be used where possible. You should only call this function directly if you want to guarantee synchronous execution.
Parameters:
Name | Type | Description |
---|---|---|
to_format |
string | requested format |
- Overrides:
- Source:
Returns:
diary data in new format
- Type
- *
Example
console.log( diary.to("NewFormat") );
to_async(to_format) → {Promise|Object}
Convert a value to some other format
Supported formats:
- output - contents serialised for output (e.g. to a file)
- spreadsheet - binary data that can be loaded by a spreadsheet program
- (formats supported by to())
See also to(), a lower-level function that supports formats that can be generated synchronously. You can use that function if a Promise interface would be cumbersome or unnecessary in a given piece of code.
Parameters:
Name | Type | Description |
---|---|---|
to_format |
string | requested format |
- Overrides:
- Source:
Returns:
Promise that returns the converted diary
- Type
- Promise | Object
Example
diary.to_async("NewFormat").then( reformatted => console.log( reformatted_diary ) );