
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
@qntm-code/string-to-date
Advanced tools
Parse date strings including human readable dates to a Date object
Parse a wide range of date formats including human-input dates.
npm install @qntm-code/string-to-date
or
yarn add @qntm-code/string-to-date
There are two ways to use string-to-date:
1.) Return a Date
object.
parse() arguments:
| argument | type | description | optional |
|---|---|---|---|
input | string | The string to parse | no |
locale | string | The locale to use | yes |
Example:
import StringToDate from '@qntm-code/string-to-date';
StringToDate.parse('2020-10-15');
// same as new Date(2020, 9, 15, 0, 0, 0, 0)
If the string cannot be parsed, null is returned.
2.) Return an object with one or more integer values for the following keys: year, month, day, hour, minute, second, millisecond, offset.
parseToObject() arguments:
| argument | type | description | optional |
|---|---|---|---|
input | string | The string to parse | no |
locale | string | The locale to use | yes |
Example:
import StringToDate from '@qntm-code/string-to-date'
StringToDate.parseToObject('15 Oct 2020 at 6pm');
// returns:
{
year: 2020,
month: 10,
day: 15,
hour: 18,
}
If the string cannot be parsed, null is returned.
Summary:
Exhaustive list of date formats
string-to-date supports any locale that your runtime's Intl (ECMAScript
Internationalization API) supports. In browsers that usually means the operating
system language. In Node, that means the compiled language or the icu modules
included.
string-to-date has an addFormat() function to add a custom parser.
First, parsers must have matcher or template.
matcher: A RegExp to match a stringtemplate: A string with template variables such as _YEAR_ _MONTH_ etc.
that will be converted to a regular expressionSecond, parsers must have units or handler.
units: An array of unit strings to fit matches into (year, month, day, etc.)handler: A function that takes matches and returns an object with keys year,
month, day etc.import StringToDate from '@qntm-code/string-to-date';
parser.addFormat(
new Format({
matcher: /^(\d+) days? into month (\d+) in year (\d{4})$/,
units: ['day', 'month', 'year'],
})
);
Keep in mind that \d does not support other numbering system such as Chinese
or Bengali. To support those you can use the template option given in
example 3 and
example 4.
import StringToDate from '@qntm-code/string-to-date';
parser.addFormat(
new Format({
matcher: /^Q([1-4]) (\d{4})$/,
handler: function ([, quarter, year]) {
const monthByQuarter = { 1: 1, 2: 4, 3: 7, 4: 10 };
const month = monthByQuarter[quarter];
return { year, month };
},
})
);
import StringToDate from '@qntm-code/string-to-date';
parser.addFormat(
new Format({
template: 'The (_DAY_)(?:_ORDINAL_) day of (_MONTH_), (_YEAR_)',
units: ['day', 'month', 'year'],
})
);
import StringToDate from '@qntm-code/string-to-date';
parser.addFormat(
new Format({
template: '^Q([1-4]) (_YEAR_)$',
handler: function ([, quarter, year]) {
const monthByQuarter = { 1: 1, 2: 4, 3: 7, 4: 10 };
const month = monthByQuarter[quarter];
return { year, month };
},
})
);
To remove support for a certain format, use removeFormat()
import StringToDate, { dayMonth } from '@qntm-code/string-to-date';
parser.removeFormat(dayMonth);
To create a new parser with a limited list of formats or your own custom
formats, use new Parser
import { Parser, time24Hours, yearMonthDay, ago } from '@qntm-code/string-to-date';
const parser = new Parser();
parser.addFormats([time24Hours, yearMonthDay, ago]);
npm testContributions are welcome. Please open a GitHub ticket for bugs or feature requests. Please make a pull request for any fixes or new code you'd like to be incorporated.
24 hour time (any date format followed by a 24-hour time expression)
12 hour time (any date format followed by a 12-hour time expression)
day monthname year
monthname day year
month day year
day month year
year month day
relative time
monthname day
day monthname
month day
day month
unix timestamp
@1602604901Microsoft JSON date string
/Date(1601677889008-0700)//Date(1601677889008)/chinese
2020年09月26日2020年9月26日2020 年 9 月 26 日2017年08月31日This package is based on any-date-parser by Ken Snyder
FAQs
Parse date strings including human readable dates to a Date object
We found that @qntm-code/string-to-date 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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.