Home Reference Source Test Repository
public class | source

Log

Log stores tabular (array-of-array) data in JS memory on the browser, but streams it to disk using fs.appendFileSync() in nodejs server apps. .last is used to cache the last log row As a kind of limited guarantee of history on both platforms

Constructor Summary

Public Constructor
public

constructor(fname: string, force: boolean)

Create Log with suggested file name in browser memory or on-disk in nodejs

Member Summary

Public Members
public

data array for browser and test usage

public

fd: *

public

log file descriptor from open call

public

header array for Log, as set by setHeader(header)

public

last item written to log

public

if true, uses nodejs fs calls

Method Summary

Public Methods
public

get readable stream of string log data.

public

fromString(string: *): *

restore Log from string.

public

last value for some column recorded in Log

public

sets header row and writes it to Log for csv-style Log.

public

stringifies data for text file

public

toString(): *

get string of all data in the log.

public

writes data to Log and sets .last

Public Constructors

public constructor(fname: string, force: boolean) source

Create Log with suggested file name in browser memory or on-disk in nodejs

Params:

NameTypeAttributeDescription
fname string

Suggested file name

force boolean

true forces filesystem mode, false forces memory mode, undefined tests for 'fs' module

Public Members

public data: Array source

data array for browser and test usage

public fd: * source

public fname: number source

log file descriptor from open call

public header: string[] source

header array for Log, as set by setHeader(header)

public last: Object source

last item written to log

public useFS: boolean source

if true, uses nodejs fs calls

Public Methods

public createReadStream(Readable: Object): Object source

get readable stream of string log data. This function requires a base class parameter Readable if using with in-memory data.

Params:

NameTypeAttributeDescription
Readable Object

base class for constructing readable streams (required only if log useFS=false)

Return:

Object

readable stream of log data, in string form with newlines terminating records

public fromString(string: *): * source

restore Log from string. inverse of toString().

Params:

NameTypeAttributeDescription
string *

to convert to complete Log

Return:

*

public lastByKey(k: *): number | string | undefined source

last value for some column recorded in Log

Params:

NameTypeAttributeDescription
k *

Return:

number | string | undefined

value from last write at column position matching header for given key

public setHeader(x: string[]): Object source

sets header row and writes it to Log for csv-style Log.

Params:

NameTypeAttributeDescription
x string[]

Header array giving names of columns for future writes

Return:

Object

Returns this Log; chainable

public stringify(x: Array | number | string): string source

stringifies data for text file

Params:

NameTypeAttributeDescription
x Array | number | string

data fo write to a string output

Return:

string

stringified x data

public toString(): * source

get string of all data in the log. If useFS is true, simply read the file. If useFS is false, assemble from data.

Return:

*

string representing all log data

public write(x: Array | number | string): Object source

writes data to Log and sets .last

Params:

NameTypeAttributeDescription
x Array | number | string

data to write to Log's log file or memory

Return:

Object

returns Log object, chainable