-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcolumn.transform.js
More file actions
36 lines (32 loc) · 1.14 KB
/
column.transform.js
File metadata and controls
36 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { errorTransform } from './utils/errorTransform.js'
import { factory } from '../../utils/factory.js'
import { createColumn } from '../../function/matrix/column.js'
import { isNumber } from '../../utils/is.js'
const name = 'column'
const dependencies = ['typed', 'Index', 'matrix', 'range']
/**
* Attach a transform function to matrix.column
* Adds a property transform containing the transform function.
*
* This transform changed the last `index` parameter of function column
* from zero-based to one-based
*/
export const createColumnTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, Index, matrix, range }) => {
const column = createColumn({ typed, Index, matrix, range })
// @see: comment of column itself
return typed('column', {
'...any': function (args) {
// change last argument from zero-based to one-based
const lastIndex = args.length - 1
const last = args[lastIndex]
if (isNumber(last)) {
args[lastIndex] = last - 1
}
try {
return column.apply(null, args)
} catch (err) {
throw errorTransform(err)
}
}
})
}, { isTransformFunction: true })