linkedin / linkedin/dustjs

Add a filter support to not suppress the undefined and false values in dust references ( may extend it to lists as well )

Open
#138 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.9k
Forks
461
PR merge metrics
No merged PRs in 30d

Description

In some cases, we would like not to fail gracefully for missing values in the JSON, mostly for validating certain data exists at all times.

Even though this validation can be done on the "context", it is convenient to have a special filter to "enforce" that this value should always exist in the JSON

The only code to be modified is

```
Chunk.prototype.reference = function(elem, context, auto, filters) {
if (typeof elem === "function") {
elem = elem(this, context, null, {auto: auto, filters: filters});
if (elem instanceof Chunk) {
return elem;
}
}
if (!dust.isEmpty(elem)) {
return this.write(dust.filter(elem, auto, filters));
} else {
return this;
}
};
```

Related to : https://github.com/linkedin/dustjs/issues/135

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Chunk.prototype.reference and trace how dust.filter handles undefined and false values. Read related issue #135 for context on the requested enforcement behavior. Done means a filter can preserve those values instead of suppressing them, with list handling clarified if it is included.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.