CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-js

Micro check library providing comprehensive type checking and validation operations across different JavaScript environments

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

date-time.mddocs/

Date and Time

Comprehensive date validation including relative time checks, specific date matching, and time range validation.

Capabilities

Relative Time Checks

Today Check

Checks if the given date represents today.

/**
 * Checks if the given date object indicates today
 * @param date - Date object to check
 * @returns True if date is today
 * Interfaces: not, all, any
 */
function today(date: Date): boolean;

Usage Example:

const today = new Date();
is.today(today);            // true

const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
is.today(yesterday);        // false
is.not.today(yesterday);    // true
is.all.today(today, today); // true
is.any.today(today, yesterday); // true

Yesterday Check

Checks if the given date represents yesterday.

/**
 * Checks if the given date object indicates yesterday
 * @param date - Date object to check
 * @returns True if date is yesterday
 * Interfaces: not, all, any
 */
function yesterday(date: Date): boolean;

Usage Example:

const today = new Date();
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));

is.yesterday(yesterday);    // true
is.yesterday(today);        // false
is.not.yesterday(today);    // true

Tomorrow Check

Checks if the given date represents tomorrow.

/**
 * Checks if the given date object indicates tomorrow
 * @param date - Date object to check
 * @returns True if date is tomorrow
 * Interfaces: not, all, any
 */
function tomorrow(date: Date): boolean;

Usage Example:

const today = new Date();
const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));

is.tomorrow(tomorrow);      // true
is.tomorrow(today);         // false
is.not.tomorrow(today);     // true

Past and Future Checks

Checks if the given date is in the past or future.

/**
 * Checks if the given date object indicates past
 * @param date - Date object to check
 * @returns True if date is in the past
 * Interfaces: not, all, any
 */
function past(date: Date): boolean;

/**
 * Checks if the given date object indicates future
 * @param date - Date object to check
 * @returns True if date is in the future
 * Interfaces: not, all, any
 */
function future(date: Date): boolean;

Usage Example:

const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1));

is.past(yesterday);         // true
is.future(tomorrow);        // true
is.not.past(tomorrow);      // true
is.not.future(yesterday);   // true

Specific Date Matching

Day Check

Checks if the given date matches a specific day of the week.

/**
 * Checks if the given date objects' day equals given dayString parameter
 * @param date - Date object to check
 * @param day - Day name (lowercase: 'monday', 'tuesday', etc.)
 * @returns True if date falls on the specified day
 * Interfaces: not
 */
function day(date: Date, day: string): boolean;

Usage Example:

const mondayObj = new Date('01/26/2015');
is.day(mondayObj, 'monday');    // true
is.day(mondayObj, 'tuesday');   // false
is.not.day(mondayObj, 'tuesday'); // true

Month Check

Checks if the given date matches a specific month.

/**
 * Checks if the given date objects' month equals given monthString parameter
 * @param date - Date object to check
 * @param month - Month name (lowercase: 'january', 'february', etc.)
 * @returns True if date falls in the specified month
 * Interfaces: not
 */
function month(date: Date, month: string): boolean;

Usage Example:

const januaryObj = new Date('01/26/2015');
is.month(januaryObj, 'january'); // true
is.month(januaryObj, 'february'); // false
is.not.month(januaryObj, 'february'); // true

Year Check

Checks if the given date matches a specific year.

/**
 * Checks if the given date objects' year equals given yearNumber parameter
 * @param date - Date object to check
 * @param year - Year number
 * @returns True if date falls in the specified year
 * Interfaces: not
 */
function year(date: Date, year: number): boolean;

Usage Example:

const year2015 = new Date('01/26/2015');
is.year(year2015, 2015);    // true
is.year(year2015, 2016);    // false
is.not.year(year2015, 2016); // true

Time Range Validation

Date Range Check

Checks if a date falls within a specified range.

/**
 * Checks if date is within given range
 * @param date - Date to check
 * @param start - Start date of range
 * @param end - End date of range
 * @returns True if date is between start and end dates
 * Interfaces: not
 */
function inDateRange(date: Date, start: Date, end: Date): boolean;

Usage Example:

const saturday = new Date('01/24/2015');
const sunday = new Date('01/25/2015');
const monday = new Date('01/26/2015');

is.inDateRange(sunday, saturday, monday); // true
is.inDateRange(saturday, sunday, monday); // false
is.not.inDateRange(saturday, sunday, monday); // true

Relative Range Checks

Checks if dates fall within relative time periods.

/**
 * Checks if the given date is between now and 7 days ago
 * @param date - Date to check
 * @returns True if date is in last week
 * Interfaces: not, all, any
 */
function inLastWeek(date: Date): boolean;

/**
 * Checks if the given date is between now and a month ago
 * @param date - Date to check
 * @returns True if date is in last month
 * Interfaces: not, all, any
 */
function inLastMonth(date: Date): boolean;

/**
 * Checks if the given date is between now and a year ago
 * @param date - Date to check
 * @returns True if date is in last year
 * Interfaces: not, all, any
 */
function inLastYear(date: Date): boolean;

/**
 * Checks if the given date is between now and 7 days later
 * @param date - Date to check
 * @returns True if date is in next week
 * Interfaces: not, all, any
 */
function inNextWeek(date: Date): boolean;

/**
 * Checks if the given date is between now and a month later
 * @param date - Date to check
 * @returns True if date is in next month
 * Interfaces: not, all, any
 */
function inNextMonth(date: Date): boolean;

/**
 * Checks if the given date is between now and a year later
 * @param date - Date to check
 * @returns True if date is in next year
 * Interfaces: not, all, any
 */
function inNextYear(date: Date): boolean;

Weekend and Weekday Checks

Checks if dates fall on weekends or weekdays.

/**
 * Checks if the given date objects' day is weekend
 * @param date - Date to check
 * @returns True if date is Saturday or Sunday
 * Interfaces: not, all, any
 */
function weekend(date: Date): boolean;

/**
 * Checks if the given date objects' day is weekday
 * @param date - Date to check
 * @returns True if date is Monday through Friday
 * Interfaces: not, all, any
 */
function weekday(date: Date): boolean;

Usage Example:

const monday = new Date('01/26/2015');
const sunday = new Date('01/25/2015');

is.weekend(sunday);         // true
is.weekday(monday);         // true
is.not.weekend(monday);     // true
is.not.weekday(sunday);     // true

Special Date Checks

Leap Year Check

Checks if the given year is a leap year.

/**
 * Checks if the given year number is a leap year
 * @param year - Year number to check
 * @returns True if year is a leap year
 * Interfaces: not, all, any
 */
function leapYear(year: number): boolean;

Usage Example:

is.leapYear(2016);          // true
is.leapYear(2015);          // false
is.not.leapYear(2015);      // true
is.all.leapYear(2016, 2020); // true
is.any.leapYear(2015, 2016); // true

Quarter Check

Checks if the given date falls in a specific quarter.

/**
 * Checks if the given date is in the parameter quarter
 * @param date - Date to check
 * @param quarter - Quarter number (1-4)
 * @returns True if date falls in specified quarter
 * Interfaces: not
 */
function quarterOfYear(date: Date, quarter: number): boolean;

Usage Example:

const firstQuarter = new Date('01/26/2015');
const secondQuarter = new Date('05/26/2015');

is.quarterOfYear(firstQuarter, 1);  // true
is.quarterOfYear(secondQuarter, 1); // false
is.not.quarterOfYear(secondQuarter, 1); // true

Daylight Saving Time Check

Checks if the given date is in daylight saving time.

/**
 * Checks if the given date is in daylight saving time
 * @param date - Date to check
 * @returns True if date is in daylight saving time
 * Interfaces: not, all, any
 */
function dayLightSavingTime(date: Date): boolean;

Usage Example:

// For Turkey Time Zone
const january1 = new Date('01/01/2015');
const june1 = new Date('06/01/2015');

is.dayLightSavingTime(june1);    // true
is.dayLightSavingTime(january1); // false
is.not.dayLightSavingTime(january1); // true

docs

collection-validation.md

configuration.md

date-time.md

environment-detection.md

index.md

numeric-operations.md

pattern-matching.md

presence-checking.md

string-checking.md

type-checking.md

tile.json