Skip to content

Latest commit

 

History

History
130 lines (78 loc) · 3.16 KB

File metadata and controls

130 lines (78 loc) · 3.16 KB

SplitSymbol

Symbol which specifies a method that splits a string at the indices that match a regular expression.

Usage

var SplitSymbol = require( '@stdlib/symbol/split' );

SplitSymbol

symbol which specifies a method that splits a string at the indices that match a regular expression.

var s = typeof SplitSymbol;
// e.g., returns 'symbol'

Notes

  • The symbol is only supported in environments which support symbols. In non-supporting environments, the value is null.
  • When calling String.prototype.split and the separator argument is an object with a [SplitSymbol]() method, this method is called with the target string and limit as arguments.

Examples

var defineProperty = require( '@stdlib/utils/define-property' );
var SplitSymbol = require( '@stdlib/symbol/split' );

function splitter( str ) {
    return str.split( '-' );
}

var obj = {};

defineProperty( obj, SplitSymbol, {
    'configurable': true,
    'value': null
});

var str = 'a-b-c-d-e';
console.log( str.split( obj ) );

defineProperty( obj, SplitSymbol, {
    'configurable': true,
    'value': splitter
});
console.log( str.split( obj ) );