main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 4 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
| 5 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
| 6 | var toString = require('../internals/to-string');
|
---|
| 7 |
|
---|
| 8 | var stringSlice = uncurryThis(''.slice);
|
---|
| 9 | var max = Math.max;
|
---|
| 10 | var min = Math.min;
|
---|
| 11 |
|
---|
| 12 | // eslint-disable-next-line unicorn/prefer-string-slice -- required for testing
|
---|
| 13 | var FORCED = !''.substr || 'ab'.substr(-1) !== 'b';
|
---|
| 14 |
|
---|
| 15 | // `String.prototype.substr` method
|
---|
| 16 | // https://tc39.es/ecma262/#sec-string.prototype.substr
|
---|
| 17 | $({ target: 'String', proto: true, forced: FORCED }, {
|
---|
| 18 | substr: function substr(start, length) {
|
---|
| 19 | var that = toString(requireObjectCoercible(this));
|
---|
| 20 | var size = that.length;
|
---|
| 21 | var intStart = toIntegerOrInfinity(start);
|
---|
| 22 | var intLength, intEnd;
|
---|
| 23 | if (intStart === Infinity) intStart = 0;
|
---|
| 24 | if (intStart < 0) intStart = max(size + intStart, 0);
|
---|
| 25 | intLength = length === undefined ? size : toIntegerOrInfinity(length);
|
---|
| 26 | if (intLength <= 0 || intLength === Infinity) return '';
|
---|
| 27 | intEnd = min(intStart + intLength, size);
|
---|
| 28 | return intStart >= intEnd ? '' : stringSlice(that, intStart, intEnd);
|
---|
| 29 | }
|
---|
| 30 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.