Skip to content

Latest commit

 

History

History
138 lines (83 loc) · 3.49 KB

File metadata and controls

138 lines (83 loc) · 3.49 KB

SplitSymbol

Split symbol which is used to split a string at the indices that match the current object.

Usage

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

SplitSymbol

Split symbol which is used to split a string at the indices that match the current object.

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

Notes

  • This symbol is only supported in environments which support symbols. In non-supporting environments, the value is null.

  • The split operator uses the following algorithm to determine the return value of string.split( object ):

    • If object has [SplitSymbol]() method then the same method is called.
    • Otherwise, if object does not have a [SplitSymbol]() method (i.e., object[SplitSymbol] is null or undefined), the String.prototype.split() method determines the result .

Examples

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

function split( str) {
    return str.split(" ");>
}

var obj = {};

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

var str = 'hello how';
console.log( str.split( obj ) );
// => [ 'hello how' ]

defineProperty( obj, SplitSymbol, {
    'configurable': true,
    'value': split
});
console.log( str.split( obj ) );
// => [ 'hello', 'how' ]