Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
The de-indent npm package is a utility for removing leading indentation from multiline strings. This can be particularly useful when dealing with template literals in JavaScript, where you want to maintain readability in your code without preserving the indentation in the resulting string.
Basic De-indentation
This feature removes the leading indentation from a multiline string, making it easier to work with template literals without preserving the indentation in the final string.
const deindent = require('de-indent');
const indentedString = `
function example() {
console.log('Hello, world!');
}
`;
const result = deindent(indentedString);
console.log(result);
De-indentation with Template Literals
This feature is useful for de-indenting HTML or XML strings defined using template literals, making the code more readable while ensuring the final string has no leading spaces.
const deindent = require('de-indent');
const indentedString = `
<div>
<p>Hello, world!</p>
</div>
`;
const result = deindent(indentedString);
console.log(result);
The strip-indent package is another utility for removing leading whitespace from multiline strings. It works similarly to de-indent but offers a slightly different API. Both packages achieve the same goal, but developers might prefer one over the other based on personal preference or specific use cases.
The dedent package is a popular alternative that not only removes leading indentation but also handles escaping of backticks and interpolation of variables within template literals. It offers more features compared to de-indent, making it a more versatile choice for complex string manipulations.
FAQs
remove extra indent from a block of code
We found that de-indent demonstrated a not healthy version release cadence and project activity because the last version was released 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.