Skip to content

Examples

Live demos

Try the components right in your browser — these deploy alongside these docs:

Source

Runnable reference integrations live in the examples/ directory of the repo:

Date math

ts
import { DoranDate } from '@doranjs/core';

const start = DoranDate.fromJalali(1405, 1, 1);
const end = start.addMonths(3).endOf('month');

end.diff(start, 'day'); // number of days in Q1
start.isLeapYear(); // false

Build a custom calendar (headless)

tsx
import { buildMonthGrid } from '@doranjs/react';
import { faIR } from '@doranjs/core';

function MiniMonth({ year, month }: { year: number; month: number }) {
  const grid = buildMonthGrid(year, month);
  return (
    <table dir="rtl">
      <thead>
        <tr>
          {faIR.weekdaysMin.map((w) => (
            <th key={w}>{w}</th>
          ))}
        </tr>
      </thead>
      <tbody>
        {grid.weeks.map((week, i) => (
          <tr key={i}>
            {week.map((cell) => (
              <td key={cell.date.epochMs} style={{ opacity: cell.inCurrentMonth ? 1 : 0.4 }}>
                {cell.date.format('D')}
              </td>
            ))}
          </tr>
        ))}
      </tbody>
    </table>
  );
}

Natural language → calendar

ts
import { parse } from '@doranjs/nlp';

const result = parse('جمعه ساعت ۷ شب');
if (result && result.confidence > 0.8) {
  scheduleMeeting(result.date.toGregorian());
}

Highlight holidays

ts
import { getHolidays } from '@doranjs/holidays';

const official = getHolidays(1405).filter((h) => h.official);

Form validation with zod

zDoranDate() coerces any date input (ISO string, Date, epoch, or DoranDate) into a DoranDate and drops into any zod-based form stack. See @doranjs/zod for details.

ts
import { z } from 'zod';
import { zDoranDate } from '@doranjs/zod';

const Booking = z.object({
  checkIn: zDoranDate({ min: '2024-01-01' }),
  checkOut: zDoranDate(),
});

const { checkIn } = Booking.parse({ checkIn: '2024-06-28', checkOut: new Date() });
checkIn.toISOString(); // Gregorian ISO for your backend

Last updated:

Released under the MIT License.