UNPKG

915 BJavaScriptView Raw
1'use strict'
2
3const errorTransform = require('./error.transform').transform
4
5/**
6 * Attach a transform function to matrix.row
7 * Adds a property transform containing the transform function.
8 *
9 * This transform changed the last `index` parameter of function row
10 * from zero-based to one-based
11 */
12function factory (type, config, load, typed) {
13 const row = load(require('../../function/matrix/row'))
14
15 // @see: comment of row itself
16 return typed('row', {
17 '...any': function (args) {
18 // change last argument from zero-based to one-based
19 const lastIndex = args.length - 1
20 const last = args[lastIndex]
21 if (type.isNumber(last)) {
22 args[lastIndex] = last - 1
23 }
24
25 try {
26 return row.apply(null, args)
27 } catch (err) {
28 throw errorTransform(err)
29 }
30 }
31 })
32}
33
34exports.name = 'row'
35exports.path = 'expression.transform'
36exports.factory = factory