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.
@types/date-fns
Advanced tools
Stub TypeScript definitions entry for date-fns, which provides its own types definitions
@types/date-fns provides TypeScript type definitions for the date-fns library, which is a modern JavaScript date utility library. It offers a wide range of functions for manipulating and formatting dates.
Date Formatting
The format function allows you to format dates in various patterns. In this example, the date is formatted to 'yyyy-MM-dd'.
import { format } from 'date-fns';
const formattedDate = format(new Date(2023, 9, 10), 'yyyy-MM-dd');
console.log(formattedDate); // Output: 2023-10-10
Date Comparison
The isAfter and isBefore functions allow you to compare dates. In this example, date1 is compared with date2 to check if it is after or before.
import { isAfter, isBefore } from 'date-fns';
const date1 = new Date(2023, 9, 10);
const date2 = new Date(2023, 9, 11);
console.log(isAfter(date1, date2)); // Output: false
console.log(isBefore(date1, date2)); // Output: true
Date Arithmetic
The addDays and subMonths functions allow you to perform arithmetic operations on dates. In this example, 5 days are added to the date and 1 month is subtracted from the date.
import { addDays, subMonths } from 'date-fns';
const date = new Date(2023, 9, 10);
const newDate1 = addDays(date, 5);
const newDate2 = subMonths(date, 1);
console.log(newDate1); // Output: 2023-10-15
console.log(newDate2); // Output: 2023-09-10
Date Parsing
The parse function allows you to parse a date string into a Date object. In this example, the date string '10-10-2023' is parsed into a Date object.
import { parse } from 'date-fns';
const dateString = '10-10-2023';
const parsedDate = parse(dateString, 'MM-dd-yyyy', new Date());
console.log(parsedDate); // Output: Tue Oct 10 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Moment.js is a widely-used library for parsing, validating, manipulating, and formatting dates. It is more feature-rich but also larger in size compared to date-fns. Moment.js uses a mutable date object, which can lead to side effects if not handled carefully.
Luxon is a modern JavaScript date and time library built by one of the Moment.js developers. It offers a more comprehensive and immutable API compared to date-fns. Luxon also supports time zones and internationalization out of the box.
Day.js is a minimalist JavaScript library that provides similar functionalities to Moment.js but with a much smaller footprint. It is immutable and chainable, making it a good alternative to date-fns for those who prefer a smaller library.
This is a stub types definition for @types/date-fns (https://github.com/date-fns/date-fns#readme).
date-fns provides its own type definitions, so you don't need @types/date-fns installed!
FAQs
Stub TypeScript definitions entry for date-fns, which provides its own types definitions
We found that @types/date-fns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.