智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export var hasOwnProperty = Object.prototype.hasOwnProperty;
  2. /**
  3. * Simpler helper method to check for a boolean type simply for the benefit of
  4. * gaining better compression when minified by not needing to have multiple
  5. * `typeof` comparisons in the codebase.
  6. */
  7. export function isBoolean(value) {
  8. return typeof value === 'boolean';
  9. }
  10. /**
  11. * Truncates the `str` at `len - ellipsisChars.length`, and adds the `ellipsisChars` to the
  12. * end of the string (by default, two periods: '..'). If the `str` length does not exceed
  13. * `len`, the string will be returned unchanged.
  14. *
  15. * @param {String} str The string to truncate and add an ellipsis to.
  16. * @param {Number} truncateLen The length to truncate the string at.
  17. * @param {String} [ellipsisChars=...] The ellipsis character(s) to add to the end of `str`
  18. * when truncated. Defaults to '...'
  19. */
  20. export function ellipsis(str, truncateLen, ellipsisChars) {
  21. var ellipsisLength;
  22. if (str.length > truncateLen) {
  23. if (ellipsisChars == null) {
  24. ellipsisChars = '…';
  25. ellipsisLength = 3;
  26. }
  27. else {
  28. ellipsisLength = ellipsisChars.length;
  29. }
  30. str = str.substring(0, truncateLen - ellipsisLength) + ellipsisChars;
  31. }
  32. return str;
  33. }
  34. /**
  35. * Removes array elements based on a filtering function. Mutates the input
  36. * array.
  37. *
  38. * Using this instead of the ES5 Array.prototype.filter() function to prevent
  39. * creating many new arrays in memory for filtering.
  40. *
  41. * @param arr The array to remove elements from. This array is mutated.
  42. * @param fn The predicate function which should return `true` to remove an
  43. * element.
  44. */
  45. export function removeWithPredicate(arr, fn) {
  46. for (var i = arr.length - 1; i >= 0; i--) {
  47. if (fn(arr[i]) === true) {
  48. arr.splice(i, 1);
  49. }
  50. }
  51. }
  52. /**
  53. * Function that should never be called but is used to check that every
  54. * enum value is handled using TypeScript's 'never' type.
  55. */
  56. /* istanbul ignore next */
  57. export function assertNever(theValue) {
  58. throw new Error("Unhandled case for value: '".concat(theValue, "'"));
  59. }
  60. //# sourceMappingURL=utils.js.map