
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
Easily build date regular expressions
drb (Date Regex Builder) is a library to aide in generating regular expressions to match dates.
Regular expressions are difficult to get right and can get messy quickly. Consider creating a regular expression to match a day of the month. A naïve attempt might be to create a regex that matches two digits:
\d{2}
But there's a problem with this - 99 matches this regular expression and is not a valid day of the month. So we must refactor this to be a little more clever:
[0-3][0-9]
This is closer to what we want, but it still matches numbers from 32 to 39.
[0-2][0-9]|3[0-1]
We're almost there. Valid dates still match correctly, and 32+ numbers are not matching, which is what we want. However, 00 generates a false-positive match when using this regex. We can finally meet all of the requirements with the following regex:
0[1-9]|[1-2][0-9]|3[0-1]
Using drb, this regex is easy to generate:
const drbMoment = drb(momentFormatter)
const regex = drbMoment('DD')
console.log(regex) // (?:(?:0[1-9]|[12][0-9]|3[01]))
Install with npm:
$ npm install --save drb
Or optionally using yarn
$ yarn add drb
Import drb and a formatter (currently only Moment.js is supported) using one of these methods:
Node.js
const { drb } = require('drb')
const { momentFormatter } = require('drb/formatters/momentFormatter')
ES6/TypeScript
import { drb } from 'drb'
import { momentFormatter } from 'drb/formatters/momentFormatter'
Now combine drb with a formatter
const drbMoment = drb(momentFormatter)
Use drbMoment to create regexes using the syntax provided by Moment.js
const regex1 = drbMoment('DD')
console.log(regex1) // (?:(?:0[1-9]|[12][0-9]|3[01]))
const regex2 = drbMoment('MM-DD-YYYY hh:mm:ss')
console.log(regex2)
// (?:(?:0[1-9]|1[0-2]))(?:-)(?:(?:0[1-9]|[12][0-9]|3[01]))(?:-)(?:\d{4})(?: )(?:(?:0[1-9]|1[0-2]))(?::)(?:(?:0[0-9]|[1-5][0-9]))(?::)(?:(?:0[0-9]|[1-5][0-9]))
MIT
FAQs
Build date regexes
We found that drb 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.