@stdlib/slice-base-int2slice
v0.2.2
Published
Convert an integer to a Slice object.
Downloads
712
Readme
int2slice
Convert an integer to a
Slice
object.
Installation
npm install @stdlib/slice-base-int2slice
Usage
var int2slice = require( '@stdlib/slice-base-int2slice' );
int2slice( value, max, strict )
Converts an integer to a Slice
object, where max
specifies the index upper bound.
var s = int2slice( -4, 10, false );
// returns <Slice>
var start = s.start;
// returns 6
var stop = s.stop;
// returns 7
var step = s.step;
// returns 1
When strict
is true
, the function returns an error object if an input value exceeds index bounds.
var s = int2slice( 100, 10, true );
// returns { 'code': 'ERR_SLICE_OUT_OF_BOUNDS' }
A returned error object may have one of the following error codes:
- ERR_SLICE_OUT_OF_BOUNDS: a slice exceeds index bounds.
Examples
var int2slice = require( '@stdlib/slice-base-int2slice' );
var s = int2slice( -1, 7, false );
console.log( '%s', s.toString() );
s = int2slice( 3, 5, false );
console.log( '%s', s.toString() );
s = int2slice( -3, 5, false );
console.log( '%s', s.toString() );
s = int2slice( 10, 5, false );
console.log( '%s', s.toString() );
s = int2slice( -10, 5, false );
console.log( '%s', s.toString() );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.