'use strict';

// MODULES //

var validate = require( './validate.js' );


// MAIN //

/**
* Multidimensional array constructor.
*
* @constructor
* @param {Options} options - function options
* @param {NonNegativeIntegerArray} options.shape - array shape
* @param {ArrayLike} [options.buffer] - underlying array buffer
* @param {string} [options.dtype] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)
* @param {NonNegativeInteger} [options.offset] - integer offset specifying where in the array buffer to begin indexing
* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)
* @param {IntegerArray} [options.strides] - index strides which specify how to access data along particular array dimensions
* @throws {TypeError} `options` argument must be an object
* @throws {TypeError} must provide valid options
* @throws {RangeError} `offset` option must not exceed number of buffer elements
* @returns {ndarray} multidimensional array
*
* @example
* TODO
*/
function ndarray( options ) {
	/* eslint-disable no-invalid-this */
	var opts;
	var err;

	if ( !(this instanceof ndarray) ) {
		if ( arguments.length ) {
			return new ndarray( options ); // eslint-disable-line no-new-cap
		}
		return new ndarray(); // eslint-disable-line no-new-cap
	}
	opts = {};
	if ( arguments.length ) {
		err = validate( opts, options );
		if ( err ) {
			throw err;
		}
	}
	// Additional option validation...
	if ( opts.offset && opts.buffer ) {
		if ( opts.offset >= opts.buffer.length ) {
			throw new RangeError( 'invalid option. `offset` option exceeds provided buffer length. Option: `' + opts.offset + '`.' );
		}
	}
	return this;
} // end FUNCTION ndarray()


// EXPORTS //

module.exports = ndarray;

@@ -535,16 +535,18 @@
 s.offset
+=0
 %5D - inte
@@ -1508,16 +1508,50 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09opts.offset = opts.offset %7C%7C 0;%0A%0A
 %09// Addi
@@ -1579,25 +1579,27 @@
 ion...%0A%09if (
- 
+%0A%09%09
 opts.offset 
@@ -1600,17 +1600,19 @@
 ffset &&
- 
+%0A%09%09
 opts.buf
@@ -1615,27 +1615,21 @@
 .buffer 
-) %7B%0A%09%09if ( 
+&&%0A%09%09
 opts.off
@@ -1653,22 +1653,22 @@
 r.length
- 
+%0A%09
 ) %7B%0A
-%09
 %09%09throw 
@@ -1783,20 +1783,16 @@
 '%60.' );%0A
-%09%09%7D%0A
 %09%7D%0A%09retu

Consolidate conditionals