Skip to content

Commit ba87a5c

Browse files
committed
Add support for new transformation functions in JavaScript and Python
1 parent 07cd112 commit ba87a5c

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

data/completion.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,15 @@ complete:
597597
desc: sBucket bucket name
598598
- name: secRepo=
599599
desc: sBucket repository
600+
- name: xjs=
601+
desc: A .js file with function code manipulating an input 'args'. Returns the transformed 'args' variable
602+
- name: xpy=
603+
desc: A .py file with Python function code manipulating an input 'args'. Returns the transformed 'args' variable
604+
- name: xfn=
605+
desc: A javascript code, receiving input as 'args' and return it's code evaluation
606+
- name: xrjs=
607+
desc: A .js file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record
608+
- name: xrpy=
609+
desc: A .py file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record
610+
- name: xrfn=
611+
desc: A javascript code, receiving each input array record as 'args' and return it's code evaluation

data/usage.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,36 @@
414414
"Option": "trim",
415415
"Type": "Boolean",
416416
"Description": "If true all the strings of the result map/list will be trimmed"
417+
},
418+
{
419+
"Option": "xjs",
420+
"Type": "String",
421+
"Description": "A .js file with function code manipulating an input 'args'. Returns the transformed 'args' variable."
422+
},
423+
{
424+
"Option": "xpy",
425+
"Type": "String",
426+
"Description": "A .py file with Python function code manipulating an input 'args'. Returns the transformed 'args' variable."
427+
},
428+
{
429+
"Option": "xfn",
430+
"Type": "String",
431+
"Description": "A javascript code, receiving input as 'args' and return it's code evaluation."
432+
},
433+
{
434+
"Option": "xrjs",
435+
"Type": "String",
436+
"Description": "A .js file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record."
437+
},
438+
{
439+
"Option": "xrpy",
440+
"Type": "String",
441+
"Description": "A .py file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record."
442+
},
443+
{
444+
"Option": "xrfn",
445+
"Type": "String",
446+
"Description": "A javascript code, receiving each input array record as 'args' and return it's code evaluation."
417447
}
418448
],
419449
[

src/docs/USAGE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ These options will change the parsed input data included any filters provided.
136136
| sortmapkeys | Boolean | If true the resulting map keys will be sorted |
137137
| spacekeys | String | Replaces spaces in keys with the provided string (for example, helpful to xml output) |
138138
| trim | Boolean | If true all the strings of the result map/list will be trimmed |
139+
| xjs | String | A .js file with function code manipulating an input 'args'. Returns the transformed 'args' variable. |
140+
| xpy | String | A .py file with Python function code manipulating an input 'args'. Returns the transformed 'args' variable. |
141+
| xfn | String | A javascript code, receiving input as 'args' and return it's code evaluation. |
142+
| xrjs | String | A .js file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record. |
143+
| xrpy | String | A .py file with function code to manipulate each input array record as 'args'. Returns the transformed 'args' record. |
144+
| xrfn | String | A javascript code, receiving each input array record as 'args' and return it's code evaluation. |
139145

140146
---
141147

src/include/transformFns.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,63 @@ var _transformFns = {
469469
}
470470
})
471471
return _r
472+
},
473+
"xjs": _r => {
474+
if (isString(params.xjs)) {
475+
if (io.fileExists(params.xjs)) {
476+
var _t = io.readFileString(params.xjs)
477+
if (isString(_t)) {
478+
var _f = new Function("args", _t + "; return args")
479+
return _f(_r)
480+
}
481+
}
482+
}
483+
return _r
484+
},
485+
"xpy": _r => {
486+
if (isString(params.xpy)) {
487+
if (io.fileExists(params.xpy)) {
488+
let __r = $py(params.xpy, { args: _r}, ["args"])
489+
$pyStop()
490+
return __r
491+
}
492+
}
493+
return _r
494+
},
495+
"xfn": _r => {
496+
if (isString(params.xfn)) {
497+
var _f = new Function("args", "return " + params.xfn)
498+
return _f(_r)
499+
}
500+
},
501+
"xrjs": _r => {
502+
if (isString(params.xrjs) && isArray(_r)) {
503+
if (io.fileExists(params.xrjs)) {
504+
let _t = io.readFileString(params.xrjs)
505+
if (isString(_t)) {
506+
let _f = new Function("args", _t + "; return args")
507+
return pForEach(_r, _f)
508+
}
509+
}
510+
}
511+
return _r
512+
},
513+
"xrpy": _r => {
514+
if (isString(params.xrpy) && isArray(_r)) {
515+
if (io.fileExists(params.xrpy)) {
516+
$pyStart()
517+
let __r = pForEach(_r, r => $py(params.xrpy, { args: r}, ["args"]) )
518+
$pyStop()
519+
return __r
520+
}
521+
}
522+
return _r
523+
},
524+
"xrfn": _r => {
525+
if (isString(params.xrfn) && isArray(_r)) {
526+
let _f = new Function("args", "return " + params.xrfn)
527+
return pForEach(_r, _f)
528+
}
529+
return _r
472530
}
473531
}

0 commit comments

Comments
 (0)