Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
extract-date
Advanced tools
Extracts date from an arbitrary text input.
I am creating a large scale data aggregation platform (https://applaudience.com/). I have observed that the date-matching patterns and site specific date validation logic is repeating and could be abstracted into a universal function as long as minimum information about the expected pattern is provided (such as the direction
configuration). My motivation for creating such abstraction is to reduce the amount of repetitive logic that we use to extract dates from multiple sources.
The intended use case is extracting date of future events from blobs of text that may contain auxiliary information, e.g. 'Event at 14:00 2019-01-01 (2D)'.
The emphasis on the future events is because resolving dates such 'today' (relative dates) and 'Wednesday' (weekday dates) requires knowing the offset date. If your input sources refer predominantly to future events, then the ambiguity can be resolved using the present date.
import extractDate from 'extract-date';
extractDate('extracts date from anywhere within the input 2000-01-02');
// [{date: '2000-01-02'}]
extractDate('extracts multiple dates located anywhere within the input: 2000-01-02, 2000-01-03');
// [{date: '2000-01-02'}, {date: '2000-01-03'}]
extractDate('ignores ambiguous dates 02/01/2000');
// []
extractDate('uses `direction` to resolve ambiguous dates 02/01/2000', {direction: 'DMY'});
// [{date: '2000-01-02'}]
extractDate('uses `timezone` to resolve relative dates such as today or tomorrow', {timezone: 'Europe/London'});
// [{date: '2000-01-02'}, {date: '2000-01-03'}] (assuming that today is 2000-01-02)
extractDate('extracts dates using locales May 1, 2017', {locale: 'en'});
// [{date: '2015-05-01'}]
Name | Description | Default |
---|---|---|
direction | Token identifying the order of numeric date attributes within the string. Possible values: DM, DMY, DYM, MD, YDM, YMD. Used to resolve ambiguous dates, e.g. DD/MM/YYYY and MM/DD/YYYY. | N/A |
locale | Required when date includes localized names (e.g. month names) | N/A |
maximumAge | See Date resolution without year. | Infinity |
minimumAge | See Date resolution without year. | Infinity |
timezone | TZ database name. Used to resolve relative dates ("Today", "Tomorrow"). | N/A |
When year is not part of the input (e.g. March 2nd), then minimumAge
and maximumAge
configuration determines the year value.
minimumAge
, then the year value is equal to the current year +1.maximumAge
, then the year value is equal to the current year -1.Example:
If the current date is 2000-12-01 and the parsed date is 10-01, then the month difference is -2.
minimumAge
is 2, then the final date is 2001-10-01.minimumAge
is 3, then the final date is 2000-10-01.If the current date is 2000-01-01 and the input date is 10-01, then the month difference is 9.
maximumAge
is 10, then the final date is 2000-10-01.maximumAge
is 9, then the final date is 1999-10-01.Note: minimumAge
comparison is done using absolute difference value.
Note: This section of the documentation is included for contributors.
extract-date
includes a collection of formats (./src/createFormats.js
).extract-date
splits input string into a collection of slices pairing words into phrases of the required length.Example:
Given input "foo bar baz qux" and format:
{
direction: 'YMD',
localised: false,
dateFnsFormat: 'YYYY MM.DD',
wordCount: 2,
yearIsExplicit: true
}
Input is broken down into:
collection and the format is attempted against each phrase until a match is found.
Field | Description |
---|---|
direction | Identifies the order of numeric date attributes within the string. Possible values: DMY, DYM, YDM, YMD. Used to resolve ambiguous dates, e.g. DD/MM/YYYY and MM/DD/YYYY. |
localised | Identifies if the date is localised, i.e. includes names of the week day or month. A format that is localised is used only when locale configuration is provided. |
dateFnsFormat | Identifies date-fns format used to attempt date extraction. |
wordCount | Identifies how many words make up the date format. |
yearIsExplicit | Identifies whether the date format includes year. |
Example formats:
{
direction: 'YMD',
localised: false,
dateFnsFormat: 'YYYY.MM.DD',
wordCount: 1,
yearIsExplicit: true
},
{
direction: 'DD MMMM',
localised: true,
dateFnsFormat: 'DD MMMM',
wordCount: 2,
yearIsExplicit: false
},
extract-price
– Extracts price from an arbitrary text input.extract-time
– Extracts time from an arbitrary text input.FAQs
Extracts date from an arbitrary text input.
The npm package extract-date receives a total of 650 weekly downloads. As such, extract-date popularity was classified as not popular.
We found that extract-date 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.