Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

string-trim.js 1.2KB

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