Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
976 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
4 | var toInteger = require('../internals/to-integer');
|
---|
5 | var toString = require('../internals/to-string');
|
---|
6 |
|
---|
7 | var slice = ''.slice;
|
---|
8 | var max = Math.max;
|
---|
9 | var min = Math.min;
|
---|
10 |
|
---|
11 | // `String.prototype.substr` method
|
---|
12 | // https://tc39.es/ecma262/#sec-string.prototype.substr
|
---|
13 | $({ target: 'String', proto: true }, {
|
---|
14 | substr: function substr(start, length) {
|
---|
15 | var that = toString(requireObjectCoercible(this));
|
---|
16 | var size = that.length;
|
---|
17 | var intStart = toInteger(start);
|
---|
18 | var intLength, intEnd;
|
---|
19 | if (intStart === Infinity) intStart = 0;
|
---|
20 | if (intStart < 0) intStart = max(size + intStart, 0);
|
---|
21 | intLength = length === undefined ? size : toInteger(length);
|
---|
22 | if (intLength <= 0 || intLength === Infinity) return '';
|
---|
23 | intEnd = min(intStart + intLength, size);
|
---|
24 | return intStart >= intEnd ? '' : slice.call(that, intStart, intEnd);
|
---|
25 | }
|
---|
26 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.