Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fsubal/dayjs-range-support

Add dayjs.range() to yield each days between some period
https://github.com/fsubal/dayjs-range-support

Last synced: about 1 month ago
JSON representation

Add dayjs.range() to yield each days between some period

Awesome Lists containing this project

README

        

# dayjs-range-support

Add `dayjs.range()` to yield each day between some period

```
npm install -S @fsubal/dayjs-range-support
```

```
yarn add @fsubal/dayjs-range-support
```

## Usage

`dayjs.range()` returns a **generator** (not `dayjs.Dayjs[]`)!

```ts
Array.from(dayjs.range('2020-12-01', '2020-12-31'))
[...dayjs.range('2020-12-01', '2020-12-31')]

for (const day of dayjs.range('2020-12-01', '2020-12-31')) {
...
}
```

```ts
dayjs.range("2020-12-01", "2020-12-12", {
step: [2, "day"],
});
```

## Options

`dayjs.range()` accepts options as the 3rd argument.

### `excludeEnd`: boolean (optional)

Whether to exclude the last date from range.

### `step`: [number, string] (optional)

Step between each date. Accepts the same type as `dayjs.add()` ( For example, `[2, 'day']` ).