Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@area17/parse-numeric-date
Advanced tools
Micro library to parse numeric based date inputs ~4kb minified/~1kb gzip
Date entry is hard for users. Date pickers, including the native one, aren't always the best for accessibility.
In his article "Maybe You Don't Need a Date Picker", Adrian Roselli proposes using a text field which users enter a date into, some client side does some parsing and then some feedback is presented to the user.
It is fairly straight forward to parse a known date format and convert to ISO format. But, what if users don't enter the date in your known format?
Well, that is what parse-numeric-date
attempts to solve.
https://area17.github.io/parse-numeric-date/
Firstly, install via npm:
$ npm install @area17/parse-numeric-date
Import into your JavaScript by:
import parseNumericDate from '@area17/parse-numeric-date'
And then in your JavaScript:
let isoString = parseNumericDate('29/12/25'); // 2025-12-29
If you want to have manual control over the locale:
let isoString = parseNumericDate('29/12/25', {
locale: 'en-GB' // will favor d/m/y over m/d/y
}); // 2025-12-29
parse-numeric-date
can parse13. 12. 2022
This parse-numeric-date
works with a big assumption:
Dates closer to today are better than dates years into the future
Date pickers for hotels, restaurants or events tend to be for things happening this year or next year. Dates of birth tend to happen from now to 100 years in the past. Retirement ages, mortgage completions tend to happen from now to 100 years in the future.
If the year difference is larger than 100, its probably useless. eg: a 29 in the string appear as 2922 rather than 29th of a month, 2022
parse-numeric-date
can't take natural input such as "December 12, 2022" - it is purely for parsing numeric inputs. Another assumption here is that such date entry, although natural in speech, isn't so natural to type - especially if the keyboard has been switched to a numeric keyboard on the users device.
If you want such parsing, perhaps you need:
Both are excellent, but can't parse numeric dates quite as fully as parse-numeric-date
.
You can see a comparison between parse-numeric-date
, anyDateParser
, parse-dob
and chrono-node
over on Codepen: Date parse testing
parse-dob
by @HenrikJoreteg was a great inspiration, we think that forking parse-dob
and removing the previous date restriction would be very interesting.
Written using Jest with tests in /test/
.
To run:
$ npm run test
Thanks to @Mohsen Alyafei for his Persian to Gregorian conversion function on Stackoverflow.
AREA 17 is dedicated to building a welcoming, diverse, safe community. We expect everyone participating in the AREA 17 community to abide by our Code of Conduct. Please read it. Please follow it.
FAQs
Parse numeric based date inputs
We found that @area17/parse-numeric-date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.