str2multislice
Parse a string-serialized
MultiSlice
object.
Usage
var str2multislice = require( '@stdlib/slice/base/str2multislice' );
str2multislice( str )
Parses a string-serialized MultiSlice
object.
var s = str2multislice( 'MultiSlice(0,Slice(2,10,1),1)' );
// returns <MultiSlice>
var d = s.data;
// returns [ 0, <Slice>, 1 ]
The function returns null
if provided an invalid string.
var s = str2multislice( 'MultiSlice(foo,bar)' );
// returns null
Notes
The string serialization format must match that of a
MultiSlice
object.var Slice = require( '@stdlib/slice/ctor' ); var MultiSlice = require( '@stdlib/slice/multi' ); var s = new MultiSlice( null, new Slice( 2, 10, 1 ), 10 ); // returns <MultiSlice> var str = s.toString(); // returns 'MultiSlice(null,Slice(2,10,1),10)'
Examples
var str2multislice = require( '@stdlib/slice/base/str2multislice' );
var s = str2multislice( 'MultiSlice(null,null,null)' );
var d = s.data;
// returns [ null, null, null ]
s = str2multislice( 'MultiSlice(10,Slice(2,10,1),null)' );
d = s.data;
// returns [ 10, <Slice>, null ]
s = str2multislice( 'MultiSlice(2,Slice(2,10,1),-5)' );
d = s.data;
// returns [ 2, <Slice>, -5 ]
s = str2multislice( 'MultiSlice(foo,bar)' );
// returns null