source: imaps-frontend/node_modules/core-js/internals/string-trim.js

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
RevLine 
[79a0317]1'use strict';
2var uncurryThis = require('../internals/function-uncurry-this');
3var requireObjectCoercible = require('../internals/require-object-coercible');
4var toString = require('../internals/to-string');
5var whitespaces = require('../internals/whitespaces');
6
7var replace = uncurryThis(''.replace);
8var ltrim = RegExp('^[' + whitespaces + ']+');
9var rtrim = RegExp('(^|[^' + whitespaces + '])[' + whitespaces + ']+$');
10
11// `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` methods implementation
12var createMethod = function (TYPE) {
13 return function ($this) {
14 var string = toString(requireObjectCoercible($this));
15 if (TYPE & 1) string = replace(string, ltrim, '');
16 if (TYPE & 2) string = replace(string, rtrim, '$1');
17 return string;
18 };
19};
20
21module.exports = {
22 // `String.prototype.{ trimLeft, trimStart }` methods
23 // https://tc39.es/ecma262/#sec-string.prototype.trimstart
24 start: createMethod(1),
25 // `String.prototype.{ trimRight, trimEnd }` methods
26 // https://tc39.es/ecma262/#sec-string.prototype.trimend
27 end: createMethod(2),
28 // `String.prototype.trim` method
29 // https://tc39.es/ecma262/#sec-string.prototype.trim
30 trim: createMethod(3)
31};
Note: See TracBrowser for help on using the repository browser.