engine/templates Override version of nucleus/templates/page.html

Members

TableWrapper

TABLE FUNCTIONS


Functions that interpret or manipulate a Google Sheet.

These functions are time-intensive and can be costly to test.

DataManager

DATA MANAGER


Functions that manipulate objects or perform important checks.

These are functions that support the interpretation of data from and to the tables.

Functions

initialize(options)bool

Initialize Ob2SS with options.

This initialization takes an options object. Options include:

  • sheetKey: [string] This is the key to a spreadsheet you want to use.
  • headerOffset: [int] What header offset to use. Default is 0.

Examples:

  • Ob2SS.initialize() Creates a companion spreadsheet for this script. Uses it every time.
  • Ob2SS.initialize({ sheetKey: 'YOUR_SHEET_KEY' }) Reads/writes data on that spreadsheet.

You get the idea.

getTable(type)Ob2SSTable

Returns a table from Ob2SS for read/write operations.

Each table is a sheet in the Spreadsheet provided or set up during initialization.

  • If a table doesn't exist, one will be created for you.
  • If a table does exist, Ob2SS will connect to it for reading/writing.
Ob2SSTable(options)

Constructs a new table as part of Ob2SS.

This is a constructor function for an Ob2SS "table". It's a wrapper around a sheet in Google Spreadsheets that includes create/read/update/delete functionality.

initialize(options) ⇒ bool

Initialize Ob2SS with options.

This initialization takes an options object. Options include:

  • sheetKey: [string] This is the key to a spreadsheet you want to use.
  • headerOffset: [int] What header offset to use. Default is 0.

Examples:

  • Ob2SS.initialize() Creates a companion spreadsheet for this script. Uses it every time.
  • Ob2SS.initialize({ sheetKey: 'YOUR_SHEET_KEY' }) Reads/writes data on that spreadsheet.

You get the idea.

Kind: global function
Returns: bool - Whether initialization was successful.

Param Type Description
options object An options object to control library use.

getTable(type) ⇒ Ob2SSTable

Returns a table from Ob2SS for read/write operations.

Each table is a sheet in the Spreadsheet provided or set up during initialization.

  • If a table doesn't exist, one will be created for you.
  • If a table does exist, Ob2SS will connect to it for reading/writing.

Kind: global function
Returns: Ob2SSTable - A table you can perform operations on.

Param Type Description
type string The type of data you want to read/write (think table or class).

Ob2SSTable(options)

Constructs a new table as part of Ob2SS.

This is a constructor function for an Ob2SS "table". It's a wrapper around a sheet in Google Spreadsheets that includes create/read/update/delete functionality.

Kind: global function

Param Type Description
options object An options object to control library use.

ob2SSTable.toArray() ⇒ array

Reads all objects from the table into an array.

Kind: instance method of Ob2SSTable
Returns: array - An array of all objects in the database.

ob2SSTable.getColumnAsArray(columnName) ⇒ array

Gets a column of the table as an array.

Note that this is transposed such that it returns a horizontal array representing the vertical values of a column.

Kind: instance method of Ob2SSTable
Returns: array - An array of values stored in this column.

Param Type Description
columnName string The name of the column to fetch.

ob2SSTable.count() ⇒ number

Returns the number of items in the table.

Kind: instance method of Ob2SSTable
Returns: number - The number of items in the table.

TableWrapper

TABLE FUNCTIONS


Functions that interpret or manipulate a Google Sheet.

These functions are time-intensive and can be costly to test.

Kind: global variable

TableWrapper.getDataRange(sheet) ⇒ range

Gets the data range of the sheet.

Basically this is the cell range that ISN'T headers.

Kind: static method of TableWrapper
Returns: range - A range that represents all the data after the header zone.

Param Type Description
sheet sheet The sheet to fetch from.

TableWrapper.getHeaderRange(sheet, options) ⇒ range

Gets the header range.

This is everything either

  • within the frozen rows section, or
  • above the headerOffset area.

Kind: static method of TableWrapper
Returns: range - The range of the header area.

Param Type Description
sheet sheet The sheet to fetch from.
options object The options object used by Ob2ss.

TableWrapper.getColumnRange(sheet, columnNumber) ⇒ range

Gets the range of a column.

Kind: static method of TableWrapper
Returns: range - The range of the target column.

Param Type Description
sheet sheet The sheet to fetch from.
columnNumber number The 1-based index of the column to fetch.

TableWrapper.getHeadersAsArray(range) ⇒ array

Gets the header range as an array of data.

Kind: static method of TableWrapper
Returns: array - The 1-dimensional array of headers.

Param Type Description
range range The range to get headers from.

TableWrapper.getColumnAsArray(sheet, headerRange) ⇒ array

Gets the column as an array.

Kind: static method of TableWrapper
Returns: array - The column as a 1-dimensional array.

Param Type Description
sheet sheet The sheet to fetch from.
headerRange range The range of the headers of this sheet.

TableWrapper.getDataAsArray(sheet) ⇒ array

Gets the DATA from the sheet.

Kind: static method of TableWrapper
Returns: array - The 2-dimensional array of values.

Param Type Description
sheet sheet The sheet to fetch from.

TableWrapper.getDefaultSheetKey() ⇒ range

Gets the default sheet key.

Right now this is only useful for testing, but in the long-run it can be used to get zero-config tables for prototyping.

Kind: static method of TableWrapper
Returns: range - The range of the target column.

DataManager

DATA MANAGER


Functions that manipulate objects or perform important checks.

These are functions that support the interpretation of data from and to the tables.

Kind: global variable

DataManager.objectToRow(flatObj, headers) ⇒ array

Converts a flat object into a row.

Kind: static method of DataManager
Returns: array - The 1-dimensional, ordered array of object properties.

Param Type Description
flatObj object A flattened object to convert.
headers array The array of headers to key against.

DataManager.isNoWrite(value, header) ⇒ boolean

Determines if a value or field type should not be written.

Kind: static method of DataManager
Returns: boolean - Whether the situation is a no-write.

Param Type Description
value primitive The number or string to be written.
header string The header name.

DataManager.isNoRead(header) ⇒ boolean

Determines if a value or field type should not be read.

Kind: static method of DataManager
Returns: boolean - Whether the situation is a no-read.

Param Type Description
header string The header name.

DataManager.objectsToRows(flatObjs, headers) ⇒ array

Converts an array of flat objects into an array of row arrays.

Kind: static method of DataManager
Returns: array - An array of arrays of ordered of object properties.

Param Type Description
flatObjs array An array of flattened objects to convert.
headers array The array of headers to key against.

DataManager.rowToObject(row, headers) ⇒ object

Converts a row into an object.

Kind: static method of DataManager
Returns: object - The unflattened object.

Param Type Description
row array The row array to convert.
headers array The array of headers to key against.

DataManager.rowsToObjects(rows, headers) ⇒ array

Multiple property arrays into an array of unflattened objects.

Kind: static method of DataManager
Returns: array - An array of unflattened objects.

Param Type Description
rows array The array of property arrays to convert.
headers array The array of headers to key against.

DataManager.flattenObject(obj) ⇒ object

Unfolds arrays and objects into a flattened object.

Objects often have nested values like arrays and objects. This process "unfolds" those objects into flattened versions that can be written to a row of data in a spreadsheet. See tests for examples.

Kind: static method of DataManager
Returns: object - The flattened object.

Param Type Description
obj object The object to flatten.

DataManager.unflattenObject(flatObj) ⇒ object

Reverses the flattening process.

This process un-nests the data in a row into a "reconstituted" object.

Kind: static method of DataManager
Returns: object - The unflattened object.

Param Type Description
flatObj object The object to unflatten.

DataManager.trimObject(obj) ⇒ object

Recurses through an object's properties and trims away undefined or null values.

Kind: static method of DataManager
Returns: object - The trimmed object.

Param Type Description
obj object The object to trim.

DataManager.sanitize(value) ⇒ string

Sanitizes strings to be written to spreadsheets.

TODO: This is currently unused, but works.

Kind: static method of DataManager
Returns: string - The sanitized version of the input.

Param Type Description
value string The string or value to sanitize

DataManager.isEmpty(obj) ⇒ boolean

Determines if an object is empty.

Kind: static method of DataManager
Returns: boolean - Whether the object is indeed empty.

Param Type Description
obj object The object to evaluate.

DataManager.removeDupes(arr) ⇒ array

Removes duplicates from an array.

TODO: This is unused, but will be an important part of extending headers when adding new objects to an Ob2SS table.

Kind: static method of DataManager
Returns: array - The deduplicated array.

Param Type Description
arr array The array to deduplicate.