Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
nunjucks-date-filter
Advanced tools
This defines a date
filter for Nunjucks
implementing moment.js, a rich date manager.
You may install this plugin with this command:
npm install nunjucks-date-filter --save-dev
You must first include the filter and then add it to your nunjucks environment:
var dateFilter = require('nunjucks-date-filter');
var env = new nunjucks.Environment();
env.addFilter('date', dateFilter);
A shortcut is proposed in the package:
var dateFilter = require('nunjucks-date-filter');
dateFilter.install(
[ env ] // by default, current nunjucks environment will be used
[ , custom_filter_name ] // by default, the filter will be named "date"
);
You can also define a default date format:
var dateFilter = require('nunjucks-date-filter');
dateFilter.setDefaultFormat('YYYY');
Once it is installed, you can call the filter in your nunjucks templates:
// with no format
This blog has been created at {{ creation_date | date }}.
// with a custom format
This blog has been created at {{ creation_date | date("YYYY") }}.
// with an addition first
This blog has been created at {{ creation_date | date("add", 7, "days") | date }}.
The moment library proposes a large set of date formats you can use to customize the filter output. It also embeds a huge set of methods to manipulate dates. Any of these methods can be called using the filter, passing as many arguments as needed (see example above).
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Mocha.
FAQs
A 'date' filter for Nunjucks implementing moment.js
We found that nunjucks-date-filter 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.