blob: 113dcf82b82d823bee32c607bcd897bc6e36548a [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var trimStart = require('string.prototype.trimstart');
4var trimEnd = require('string.prototype.trimend');
5
6var GetIntrinsic = require('get-intrinsic');
7
8var $TypeError = GetIntrinsic('%TypeError%');
9
10var RequireObjectCoercible = require('./RequireObjectCoercible');
11var ToString = require('./ToString');
12
13// https://262.ecma-international.org/10.0/#sec-trimstring
14
15module.exports = function TrimString(string, where) {
16 var str = RequireObjectCoercible(string);
17 var S = ToString(str);
18 var T;
19 if (where === 'start') {
20 T = trimStart(S);
21 } else if (where === 'end') {
22 T = trimEnd(S);
23 } else if (where === 'start+end') {
24 T = trimStart(trimEnd(S));
25 } else {
26 throw new $TypeError('Assertion failed: invalid `where` value; must be "start", "end", or "start+end"');
27 }
28 return T;
29};