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-multibyte.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var uncurryThis = require('../internals/function-uncurry-this');
  3. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  4. var toString = require('../internals/to-string');
  5. var requireObjectCoercible = require('../internals/require-object-coercible');
  6. var charAt = uncurryThis(''.charAt);
  7. var charCodeAt = uncurryThis(''.charCodeAt);
  8. var stringSlice = uncurryThis(''.slice);
  9. var createMethod = function (CONVERT_TO_STRING) {
  10. return function ($this, pos) {
  11. var S = toString(requireObjectCoercible($this));
  12. var position = toIntegerOrInfinity(pos);
  13. var size = S.length;
  14. var first, second;
  15. if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined;
  16. first = charCodeAt(S, position);
  17. return first < 0xD800 || first > 0xDBFF || position + 1 === size
  18. || (second = charCodeAt(S, position + 1)) < 0xDC00 || second > 0xDFFF
  19. ? CONVERT_TO_STRING
  20. ? charAt(S, position)
  21. : first
  22. : CONVERT_TO_STRING
  23. ? stringSlice(S, position, position + 2)
  24. : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
  25. };
  26. };
  27. module.exports = {
  28. // `String.prototype.codePointAt` method
  29. // https://tc39.es/ecma262/#sec-string.prototype.codepointat
  30. codeAt: createMethod(false),
  31. // `String.prototype.at` method
  32. // https://github.com/mathiasbynens/String.prototype.at
  33. charAt: createMethod(true)
  34. };