polyfill.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function CustomEvent ( event, params ) {
  2. params = params || { bubbles: false, cancelable: false, detail: undefined };
  3. var evt = document.createEvent( 'CustomEvent' );
  4. evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
  5. return evt;
  6. }
  7. if ( typeof window.CustomEvent !== "function" ) {
  8. CustomEvent.prototype = window.Event.prototype;
  9. window.CustomEvent = CustomEvent;
  10. }
  11. if (!String.prototype.includes) {
  12. String.prototype.includes = function(search, start) {
  13. 'use strict';
  14. if (typeof start !== 'number') {
  15. start = 0;
  16. }
  17. if (start + search.length > this.length) {
  18. return false;
  19. } else {
  20. return this.indexOf(search, start) !== -1; // eslint-disable-line lodash/prefer-includes
  21. }
  22. };
  23. }
  24. if (!String.prototype.endsWith) {
  25. String.prototype.endsWith = function (searchString, position) {
  26. var subjectString = this.toString();
  27. if (position === undefined || position > subjectString.length) {
  28. position = subjectString.length;
  29. }
  30. position -= searchString.length;
  31. var lastIndex = subjectString.indexOf(searchString, position);
  32. return lastIndex !== -1 && lastIndex === position;
  33. };
  34. }
  35. if (!String.prototype.startsWith) {
  36. String.prototype.startsWith = function (searchString, position) {
  37. position = position || 0;
  38. return this.substr(position, searchString.length) === searchString;
  39. };
  40. }
  41. if (!String.prototype.splitOnce) {
  42. String.prototype.splitOnce = function (delimiter) {
  43. var components = this.split(delimiter);
  44. return [components.shift(), components.join(delimiter)];
  45. };
  46. }
  47. if (!String.prototype.trim) {
  48. String.prototype.trim = function () {
  49. return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  50. };
  51. }