This commit is contained in:
2023-03-01 10:57:27 +01:00
parent f464a1671d
commit 4481c7b116
2 changed files with 44 additions and 0 deletions

31
src/garlic.js Normal file
View File

@@ -0,0 +1,31 @@
function garlic(body) {
let bodyCopy = {...body};
if (body.props) {
if (body.props.children) {
// check if children is an array
if (Array.isArray(body.props.children)) {
let newList = []
for (let i = 0; i < body.props.children.length; i++) {
// if child is a string, convert it to base64
if (typeof body.props.children[i] === 'string') {
newList.push(btoa(body.props.children[i]));
} else {
// if child is not a string, apply this function to it
newList.push(garlic(body.props.children[i]));
}
}
bodyCopy = {...bodyCopy, props: {...bodyCopy.props, children: newList}};
} else {
// if child is a string, convert it to base64
if (typeof body.props.children === 'string') {
bodyCopy = {...body, props: {...body.props, children: btoa(body.props.children)}};
} else {
bodyCopy = {...body, props: {...body.props, children: garlic(body.props.children)}};
}
}
}
}
return bodyCopy;
}
export default garlic;

13
src/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "garlic",
"version": "1.0.0",
"description": "",
"main": "garlic.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["garlic", "protection"],
"author": "",
"license": "ISC"
}