column.transform.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { errorTransform } from './utils/errorTransform.js';
  2. import { factory } from '../../utils/factory.js';
  3. import { createColumn } from '../../function/matrix/column.js';
  4. import { isNumber } from '../../utils/is.js';
  5. var name = 'column';
  6. var dependencies = ['typed', 'Index', 'matrix', 'range'];
  7. /**
  8. * Attach a transform function to matrix.column
  9. * Adds a property transform containing the transform function.
  10. *
  11. * This transform changed the last `index` parameter of function column
  12. * from zero-based to one-based
  13. */
  14. export var createColumnTransform = /* #__PURE__ */factory(name, dependencies, _ref => {
  15. var {
  16. typed,
  17. Index,
  18. matrix,
  19. range
  20. } = _ref;
  21. var column = createColumn({
  22. typed,
  23. Index,
  24. matrix,
  25. range
  26. });
  27. // @see: comment of column itself
  28. return typed('column', {
  29. '...any': function any(args) {
  30. // change last argument from zero-based to one-based
  31. var lastIndex = args.length - 1;
  32. var last = args[lastIndex];
  33. if (isNumber(last)) {
  34. args[lastIndex] = last - 1;
  35. }
  36. try {
  37. return column.apply(null, args);
  38. } catch (err) {
  39. throw errorTransform(err);
  40. }
  41. }
  42. });
  43. }, {
  44. isTransformFunction: true
  45. });