Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

codepointat.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*! https://mths.be/codepointat v0.2.0 by @mathias */
  2. if (!String.prototype.codePointAt) {
  3. (function() {
  4. 'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
  5. var defineProperty = (function() {
  6. // IE 8 only supports `Object.defineProperty` on DOM elements
  7. try {
  8. var object = {};
  9. var $defineProperty = Object.defineProperty;
  10. var result = $defineProperty(object, object, object) && $defineProperty;
  11. } catch(error) {}
  12. return result;
  13. }());
  14. var codePointAt = function(position) {
  15. if (this == null) {
  16. throw TypeError();
  17. }
  18. var string = String(this);
  19. var size = string.length;
  20. // `ToInteger`
  21. var index = position ? Number(position) : 0;
  22. if (index != index) { // better `isNaN`
  23. index = 0;
  24. }
  25. // Account for out-of-bounds indices:
  26. if (index < 0 || index >= size) {
  27. return undefined;
  28. }
  29. // Get the first code unit
  30. var first = string.charCodeAt(index);
  31. var second;
  32. if ( // check if it’s the start of a surrogate pair
  33. first >= 0xD800 && first <= 0xDBFF && // high surrogate
  34. size > index + 1 // there is a next code unit
  35. ) {
  36. second = string.charCodeAt(index + 1);
  37. if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
  38. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  39. return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
  40. }
  41. }
  42. return first;
  43. };
  44. if (defineProperty) {
  45. defineProperty(String.prototype, 'codePointAt', {
  46. 'value': codePointAt,
  47. 'configurable': true,
  48. 'writable': true
  49. });
  50. } else {
  51. String.prototype.codePointAt = codePointAt;
  52. }
  53. }());
  54. }