Given an optional cursor and a default offset, returns the offset to use; if the cursor contains a valid offset, that will be used, otherwise it will be the default.
function getOffset(cursor, defaultOffset) {
    if (typeof cursor === 'undefined' || cursor === null) {
        return defaultOffset;
    }

    let offset = cursorToOffset(cursor);
    if (isNaN(offset)) {
        return defaultOffset;
    }

    return offset;
}