
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
An al dente indentation tag function inspired by dedent and endent.
npm install aldent
Use the aldent tag function to remove superfluous indentation from a string:
import aldent from "aldent";
aldent`
<div>
Hello world
<span>
This is some indented text
</span>
</div>
`;
Resolves to:
<div>
Hello world
<span>
This is some indented text
</span>
</div>
aldent also maintains correct indentation during string interpolation:
const innerElements = `<span>a</span>
<span>b</span>
<span>c</span>`;
aldent`
<div>
${innerElements}
</div>
`;
Resolves to:
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
Notice here, that the innerElements variable does not contain any indentation, but is correctly indented in the final output. The resulting indentation is based on the position of the ${innerElements} syntax.
If we were to indent the ${innerElements} code further, you would get this:
const innerElements = `<span>a</span>
<span>b</span>
<span>c</span>`;
aldent`
<div>
${innerElements}
</div>
`;
Resolving to:
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
This example also shows that aldent knows nothing about HTML, or any other language for that matter. It does not prettify code. We are only manipulating strings here. As such it isn't bound to any language, making it a very versatile tool when it comes to code templating/generation.
In the above examples, innerElements has not had any indentation. Had it been indented, you would need to use aldent on the inner template string as well.
Below we also showcase the aldent(foo) syntax, which is equivalent to calling aldent`${foo}`:
const innerElements = `
<span>a</span>
<span>b</span>
<span>c</span>
`;
aldent`
<div>
${aldent(innerElements)}
</div>
`;
Resolves to:
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
Again, the position of the ${aldent(innerElements)} syntax determines the indentation level of the nested aldent call.
dedent and endentTo understand where aldent is coming from, let's first compare existing solutions dedent and endent.
dedent vs endentendent was built on top of dedent to support correct indentation during string interpolation, as shown an example of earlier in the usage section.
An example of dedent's behavior:
const innerElements = `<span>a</span>
<span>b</span>
<span>c</span>`;
dedent`
<div>
${innerElements}
</div>
`;
Resolves to:
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
That is, the inner elements are not indented correctly.
Running the same code with endent, would give you correctly indented code:
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
endent vs aldentWhile aldent is dependency-free, endent depends on three other packages, dedent, fast-json-parse, and objectorarray.
endent uses these dependencies to parse JSON-values in the template string. aldent does not concern itself with json-formatting, sees this as a separate concern, and leaves it up to the user to create a wrapper function for this purpose if needed.
Apart from being dependency-free and leaving formatting up to the user, aldent differs from endent mainly by not stripping the leading spaces of the first not-purely-whitespace line of text.
For example:
endent`
</a>
</div>
</div>
`;
resolves to
</a>
</div>
</div>
whereas
aldent`
</a>
</div>
</div>
`;
resolves to
</a>
</div>
</div>
FAQs
An al dente indentation tag function
The npm package aldent receives a total of 6 weekly downloads. As such, aldent popularity was classified as not popular.
We found that aldent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.