native-dates

API / Functions

kindOf() function

Identify and narrow native-dates values across realms and bundle copies.

import { kindOf, isDateTime } from 'native-dates'core 14.9 kB min+br

Reading a value’s kind

kindOf()

kindOf(value):
  | 'datetime' | 'date' | 'time' | 'duration'
  | 'yearMonth' | 'monthDay'
  | 'dateRange' | 'datetimeRange' | 'timeRange'
  | undefined

Returns a string tag naming which type a value belongs to, or undefined for plain JavaScript values such as native dates, strings, numbers, and objects. Identifies moments, dates, times, durations, year-month and month-day values, and ranges.

inspect.js
import { date, dateRange, hours, kindOf, monthDay, now, time, yearMonth } from 'native-dates';

kindOf(now()); // 'datetime'
kindOf(date('2026-11-16')); // 'date'
kindOf(time('9:30am')); // 'time'
kindOf(hours(2)); // 'duration'
kindOf(yearMonth('2026-11')); // 'yearMonth'
kindOf(monthDay('10/17')); // 'monthDay'
kindOf(dateRange('2026-11-01', '2026-11-07')); // 'dateRange'
kindOf(new Date()); // undefined
valueunknownrequired

Any value to inspect.

'datetime' | 'date' | 'time' | 'duration' | 'yearMonth' | 'monthDay' | 'dateRange' | 'datetimeRange' | 'timeRange' | undefined

String tag for the value's kind, or undefined when value is not from this library.

Type guards

Type guards check global symbol brands rather than prototype identity, so they work reliably across realms and duplicate bundles.

isDateTime()

isDateTime(value): value is DateTime

Returns true when the value is a DateTime instance, narrowing its type in TypeScript.

import { datetime, isDateTime } from 'native-dates';

const stamp = datetime('2026-11-16T17:30:00Z');
isDateTime(stamp); // true
isDateTime('2026-11-16T17:30:00Z'); // false

isCalendarDate()

isCalendarDate(value): value is CalendarDate

Returns true when the value is a CalendarDate instance, narrowing its type in TypeScript.

import { date, isCalendarDate } from 'native-dates';

isCalendarDate(date('2026-11-16')); // true
isCalendarDate(new Date()); // false

isTime()

isTime(value): value is Time

Returns true when the value is a Time instance, narrowing its type in TypeScript.

import { isTime, time } from 'native-dates';

isTime(time('9:30am')); // true

isDuration()

isDuration(value): value is Duration

Returns true when the value is a Duration instance, narrowing its type in TypeScript.

import { hours, isDuration } from 'native-dates';

isDuration(hours(2)); // true

isYearMonth()

isYearMonth(value): value is YearMonth

Returns true when the value is a YearMonth instance, narrowing its type in TypeScript.

import { isYearMonth, yearMonth } from 'native-dates';

isYearMonth(yearMonth('2026-11')); // true

isMonthDay()

isMonthDay(value): value is MonthDay

Returns true when the value is a MonthDay instance, narrowing its type in TypeScript.

import { isMonthDay, monthDay } from 'native-dates';

isMonthDay(monthDay('10-17')); // true

isDateRange()

isDateRange(value): value is DateRange

Returns true when the value is a DateRange instance, narrowing its type in TypeScript.

import { dateRange, isDateRange } from 'native-dates';

isDateRange(dateRange('2026-11-01', '2026-11-07')); // true

isDateTimeRange()

isDateTimeRange(value): value is DateTimeRange

Returns true when the value is a DateTimeRange instance, narrowing its type in TypeScript.

import { datetimeRange, isDateTimeRange } from 'native-dates';

isDateTimeRange(datetimeRange('2026-11-16T09:00Z', '2026-11-16T10:00Z')); // true

isTimeRange()

isTimeRange(value): value is TimeRange

Returns true when the value is a TimeRange instance, narrowing its type in TypeScript.

import { isTimeRange, timeRange } from 'native-dates';

isTimeRange(timeRange('9:00am', '5:00pm')); // true

Cross-realm instanceof and brands

Standard JavaScript instanceof checks fail across iframe boundaries and duplicate bundled copies. Every class here implements [Symbol.hasInstance] over a global registry symbol, so both instanceof and the guard functions work across realms.

You can also read the exported brand symbols directly when writing custom serializers, test matchers, or generic helpers that match any range kind through IS_RANGE:

import { DateTime, IS_DATE_TIME, IS_RANGE, now, timeRange } from 'native-dates';

const current = now();
current instanceof DateTime; // true
Boolean(current[IS_DATE_TIME]); // true

const shift = timeRange('9am', '5pm');
Boolean(shift[IS_RANGE]); // true
Constant Global symbol key Matches
IS_DATE_TIME Symbol.for('native-dates/DateTime') Matches any DateTime instance.
IS_CALENDAR_DATE Symbol.for('native-dates/CalendarDate') Matches any CalendarDate instance.
IS_TIME Symbol.for('native-dates/Time') Matches any Time instance.
IS_DURATION Symbol.for('native-dates/Duration') Matches any Duration instance.
IS_YEAR_MONTH Symbol.for('native-dates/YearMonth') Matches YearMonth instances.
IS_MONTH_DAY Symbol.for('native-dates/MonthDay') Matches MonthDay instances.
IS_RANGE Symbol.for('native-dates/Range') Matches DateRange, DateTimeRange, and TimeRange instances.
IS_DATE_RANGE Symbol.for('native-dates/DateRange') Matches DateRange instances.
IS_DATE_TIME_RANGE Symbol.for('native-dates/DateTimeRange') Matches DateTimeRange instances.
IS_TIME_RANGE Symbol.for('native-dates/TimeRange') Matches TimeRange instances.
Edit this pageUpdated Nov 12, 2026