您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

utils.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.concatArgs = exports.seqEqual = void 0;
  4. /**
  5. * Check whether two sequences (e.g. Arrays of numbers) are equal.
  6. *
  7. * @param arr1 - One of the arrays to compare.
  8. * @param arr2 - The other array to compare.
  9. */
  10. function seqEqual(arr1, arr2) {
  11. if (arr1.length !== arr2.length) {
  12. return false;
  13. }
  14. for (let i = 0; i < arr1.length; i++) {
  15. if (arr1[i] !== arr2[i]) {
  16. return false;
  17. }
  18. }
  19. return true;
  20. }
  21. exports.seqEqual = seqEqual;
  22. /**
  23. * Check whether a value is a sequence (e.g. Array of numbers).
  24. *
  25. * @param val - The value to check.
  26. */
  27. function isSequence(val) {
  28. return typeof val !== 'number';
  29. }
  30. /**
  31. * Concatenate all `arguments` into a single array. Each argument can be either
  32. * a single element or a sequence, which has a `length` property and supports
  33. * element retrieval via sequence[ix].
  34. *
  35. * > concatArgs(1, [2, 3], Buffer.from([4,5]), new Uint8Array([6, 7]));
  36. * [1,2,3,4,5,6,7]
  37. *
  38. * @param args - Concatenate of these args into a single array.
  39. * @returns Array of concatenated arguments
  40. */
  41. function concatArgs(...args) {
  42. const ret = [];
  43. args.forEach((arg) => {
  44. if (isSequence(arg)) {
  45. for (const j of arg) {
  46. ret.push(j);
  47. }
  48. }
  49. else {
  50. ret.push(arg);
  51. }
  52. });
  53. return ret;
  54. }
  55. exports.concatArgs = concatArgs;
  56. //# sourceMappingURL=utils.js.map