import { ArgumentError } from './commons/ErrorModels' ; import { RangeIterator } from './commons/Iterators' ; import { IterableProtocol } from './commons/types' ; function range ( start , end ? , step ? ) { if ( typeof end === 'undefined' ) { end = start ; start = 0 ; } if ( typeof step === 'undefined' ) { if ( start < end ) { step = 1 ; } else { step = - 1 ; } } if ( validateSameRage ( start , end ) ) { throw new ArgumentError ( 'The range parameter is same.' ) ; } else if ( validateInputTypes ( start , end , step ) ) { throw new ArgumentError ( 'Please check arguments type.' ) ; } let stepFunction = step ; if ( typeof step === 'number' ) { let stepValue = step ; stepFunction = ( value ) => { return value + stepValue ; } ; } return new RangeIterator ( start , end , stepFunction ) ; } function validateSameRage ( start , end ) { return start === end ; } function validateInputTypes ( start , end ? , step ? ) { return ( typeof start !== 'number' || typeof end !== 'number' || ( typeof step !== 'number' && typeof step !== 'function' ) ) ; } export default range ;