question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Special value to ignore entry

See original GitHub issue

Thanks for a very useful module!

I’m writing a fairly complex XML-generation program and there are cases where some attributes/elements may or may not be included, depending on the business logic. Right now, in order to ignore such an entry, I need to add an explicit condition that only adds the entry in case the condition is satisfied.

A simpler way to code would be to add the entry regardless, and reserve a special value, e.g. undefined, to instruct the XML generator to ignore the entry when the special value is found.

For example, instead of writing:

const snippet = [{
  'element1': 'hello',
}];
if (condition) {
  snippet.push({ 'element2': 'goodbye' });
}

one could write:

const snippet = [{
   'element1': 'hello'
}, {
   'element2': condition ? 'goodbye' : undefined
}];

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
infojunkiecommented, Nov 13, 2020

That worked great! Thank you.

0reactions
davidcalhouncommented, Nov 13, 2020

I think I see what you’re saying. You can do this in JS like this:

// Positive condition:
toXML([
    {
        element1: 'hello'
    },
    {
        ...(true && {
            element2: 'goodbye'
        })
    }
]);
// -> '<element1>hello</element1><element2>goodbye</element2>'

// Negative condition:
toXML([
    {
        element1: 'hello'
    },
    {
        ...(false && {
            element2: 'goodbye'
        })
    }
]);
// -> '<element1>hello</element1>'
Read more comments on GitHub >

github_iconTop Results From Across the Web

What would be the best way to ignore characters in a input
If I give a input like he7ck and I want it to ignore anything that isn't letters so it just takes the input...
Read more >
Ignore Null in a Column that otherwise needs a Unique Value
The column can have many Null entries, but only one instance of each non-Null value. The workaround is to set up a second...
Read more >
Ignore certain values after a specific date
I am trying to pull volume of data entries over time for my team but some of these people have moved to other...
Read more >
Handling Null and Other Special Values - Tableau Help
A null value is a field that is blank, and signifies missing or unknown values. When you drag a measure or continuous date...
Read more >
sqlite - SQL Query: if a row contains a specific value, ignore all ...
I would like to get the distinct list of process_names that do not have a row that has an input value found in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found