-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object merge with special characters #175
base: tinker-object-merge-template
Are you sure you want to change the base?
Object merge with special characters #175
Conversation
const str = inspect(val, { depth: null, compact: true, maxArrayLength: null, maxStringLength: null }); | ||
return str | ||
.replace(/"\$\$\$([^"]+)"/g, '$1') | ||
.replace(/'\$\$\$([^']+)'/g, '$1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two lines replaces $$$var with var, so if we meet {a: "$$$var"} or {a: '$$$var'} in code it results {a: var}. Also works for {a: '$$$process.env.B = "true"'} => {a: process.env.B = "true"}
return str | ||
.replace(/"\$\$\$([^"]+)"/g, '$1') | ||
.replace(/'\$\$\$([^']+)'/g, '$1') | ||
.replace(/(['"])(.*?\$\{.*?\}.*?)\1/g, '`$2`'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we meet in resulting code "something ${a}" it changes "
to backtick (same for '
), so it will be
`something ${a}`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this! and +1 for this solution 🙌 Thanks @rin-st!
Very small down side of this is extension developers creating extension needs to follow our custom instruction for using variables:
- While accessing vars from code snipped they need to use
$$$
- If they want to use string interpolation then they need to use escape that var in string
\$
I think it's probably fine because I feel complex templating engine have it too like handlebars have {{var}}
kind of thing? Also I think most of the file won't require accessing variables from code snippet too, and if some requires then they can use this format. We can document this nicely 🙌. Also with object-merge util their wouldn't be lot of key values where they need to use this format.
Let's see what others have to say
To test:
-
switch to this branch
object-merge-special-characters
-
run this:
yarn build && yarn cli ../test-blah -s hardhat -e technophile-04/hardhat-config:v2 --skip
@rin-st this is great and working great too!! This is a simple solution! Maybe instead of using $$$var for the variables, it is better to use something like |
No description provided.