Version 1
[yaffs-website] / node_modules / core-js / modules / _string-trim.js
1 var $export = require('./_export')
2   , defined = require('./_defined')
3   , fails   = require('./_fails')
4   , spaces  = require('./_string-ws')
5   , space   = '[' + spaces + ']'
6   , non     = '\u200b\u0085'
7   , ltrim   = RegExp('^' + space + space + '*')
8   , rtrim   = RegExp(space + space + '*$');
9
10 var exporter = function(KEY, exec, ALIAS){
11   var exp   = {};
12   var FORCE = fails(function(){
13     return !!spaces[KEY]() || non[KEY]() != non;
14   });
15   var fn = exp[KEY] = FORCE ? exec(trim) : spaces[KEY];
16   if(ALIAS)exp[ALIAS] = fn;
17   $export($export.P + $export.F * FORCE, 'String', exp);
18 };
19
20 // 1 -> String#trimLeft
21 // 2 -> String#trimRight
22 // 3 -> String#trim
23 var trim = exporter.trim = function(string, TYPE){
24   string = String(defined(string));
25   if(TYPE & 1)string = string.replace(ltrim, '');
26   if(TYPE & 2)string = string.replace(rtrim, '');
27   return string;
28 };
29
30 module.exports = exporter;