|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# SplitSymbol |
| 22 | + |
| 23 | +> Split [symbol][mdn-split-symbol] which is used to split a string at the indices that match the current object. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var SplitSymbol = require( '@stdlib/symbol/split' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### SplitSymbol |
| 44 | + |
| 45 | +Split [`symbol`][mdn-split-symbol] which is used to split a string at the indices that match the current object. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var s = typeof SplitSymbol; |
| 49 | +// e.g., returns 'symbol' |
| 50 | +``` |
| 51 | + |
| 52 | +</section> |
| 53 | + |
| 54 | +<!-- /.usage --> |
| 55 | + |
| 56 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 57 | + |
| 58 | +<section class="notes"> |
| 59 | + |
| 60 | +## Notes |
| 61 | + |
| 62 | +- This [symbol][mdn-split-symbol] is only supported in environments which support [symbols][mdn-symbol]. In non-supporting environments, the value is `null`. |
| 63 | + |
| 64 | +- The `split` operator uses the following algorithm to determine the return value of `string.split( object )`: |
| 65 | + |
| 66 | + - If `object` has `[SplitSymbol]()` method then the same method is called. |
| 67 | + - 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 . |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.notes --> |
| 72 | + |
| 73 | +<!-- Package usage examples. --> |
| 74 | + |
| 75 | +<section class="examples"> |
| 76 | + |
| 77 | +## Examples |
| 78 | + |
| 79 | +<!-- eslint no-undef: "error" --> |
| 80 | + |
| 81 | +```javascript |
| 82 | +var defineProperty = require( '@stdlib/utils/define-property' ); |
| 83 | +var SplitSymbol = require( './../lib' ); |
| 84 | + |
| 85 | +function split( str) { |
| 86 | + return str.split(" ");> |
| 87 | +} |
| 88 | + |
| 89 | +var obj = {}; |
| 90 | + |
| 91 | +defineProperty( obj, SplitSymbol, { |
| 92 | + 'configurable': true, |
| 93 | + 'value': null |
| 94 | +}); |
| 95 | + |
| 96 | +var str = 'hello how'; |
| 97 | +console.log( str.split( obj ) ); |
| 98 | +// => [ 'hello how' ] |
| 99 | + |
| 100 | +defineProperty( obj, SplitSymbol, { |
| 101 | + 'configurable': true, |
| 102 | + 'value': split |
| 103 | +}); |
| 104 | +console.log( str.split( obj ) ); |
| 105 | +// => [ 'hello', 'how' ] |
| 106 | +``` |
| 107 | + |
| 108 | +</section> |
| 109 | + |
| 110 | +<!-- /.examples --> |
| 111 | + |
| 112 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 113 | + |
| 114 | +<section class="references"> |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.references --> |
| 119 | + |
| 120 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 121 | + |
| 122 | +<section class="related"> |
| 123 | + |
| 124 | +</section> |
| 125 | + |
| 126 | +<!-- /.related --> |
| 127 | + |
| 128 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 129 | + |
| 130 | +<section class="links"> |
| 131 | + |
| 132 | +[mdn-split-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split |
| 133 | + |
| 134 | +[mdn-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symvol |
| 135 | + |
| 136 | +</section> |
| 137 | + |
| 138 | +<!-- /.links --> |
0 commit comments