forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.transform.js
More file actions
28 lines (25 loc) · 1.13 KB
/
print.transform.js
File metadata and controls
28 lines (25 loc) · 1.13 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
import { createPrint } from '../../function/string/print.js'
import { factory } from '../../utils/factory.js'
import { printTemplate } from '../../utils/print.js'
const name = 'print'
const dependencies = ['typed', 'matrix', 'zeros', 'add']
export const createPrintTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, zeros, add }) => {
const print = createPrint({ typed, matrix, zeros, add })
return typed(name, {
'string, Object | Array': function (template, values) { return print(_convertTemplateToZeroBasedIndex(template), values) },
'string, Object | Array, number | Object': function (template, values, options) { return print(_convertTemplateToZeroBasedIndex(template), values, options) }
})
function _convertTemplateToZeroBasedIndex (template) {
return template.replace(printTemplate, (x) => {
const parts = x.slice(1).split('.')
const result = parts.map(function (part) {
if (!isNaN(part) && part.length > 0) {
return parseInt(part) - 1
} else {
return part
}
})
return '$' + result.join('.')
})
}
}, { isTransformFunction: true })