From 4481c7b1168f78ef04d99cd23ad393c4e663f64e Mon Sep 17 00:00:00 2001 From: Daniel Rosel Date: Wed, 1 Mar 2023 10:57:27 +0100 Subject: [PATCH] package --- src/garlic.js | 31 +++++++++++++++++++++++++++++++ src/package.json | 13 +++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/garlic.js create mode 100644 src/package.json diff --git a/src/garlic.js b/src/garlic.js new file mode 100644 index 0000000..0ed59aa --- /dev/null +++ b/src/garlic.js @@ -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; diff --git a/src/package.json b/src/package.json new file mode 100644 index 0000000..7fe9388 --- /dev/null +++ b/src/package.json @@ -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" +}