Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ziqiangwang/weekday.js
A tiny library for weekday, you can get weekday list and format it easily.Such as get all weekdays recently, weekdays within a period of time, weekdays counts...
https://github.com/ziqiangwang/weekday.js
count format range recent weekday
Last synced: 7 days ago
JSON representation
A tiny library for weekday, you can get weekday list and format it easily.Such as get all weekdays recently, weekdays within a period of time, weekdays counts...
- Host: GitHub
- URL: https://github.com/ziqiangwang/weekday.js
- Owner: ZiQiangWang
- License: mit
- Created: 2017-12-18T11:31:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-03T05:21:56.000Z (about 6 years ago)
- Last Synced: 2024-12-11T00:34:30.499Z (23 days ago)
- Topics: count, format, range, recent, weekday
- Language: JavaScript
- Homepage:
- Size: 221 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# weekday.js
A tiny library for weekday, you can get weekday list and format it easily.Such as get all weekdays recently, weekdays within a period of time, weekdays counts...[![NPM version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![NPM downloads][npm-downloads]][npm-url]
[![Coverage Status][coveralls-badge]][coveralls-url]
[![gzip](http://img.badgesize.io/https://unpkg.com/weekdayjs/lib/weekdayjs.min.js?compression=gzip)][unpkg-url][npm-badge]: https://img.shields.io/npm/v/weekdayjs.svg
[npm-url]: https://www.npmjs.com/package/weekdayjs
[npm-downloads]: https://img.shields.io/npm/dm/weekdayjs.svg
[travis-badge]: https://www.travis-ci.org/ZiQiangWang/weekday.js.svg?branch=master
[travis-url]: https://www.travis-ci.org/ZiQiangWang/weekday.js
[unpkg-url]: https://unpkg.com/weekdayjs/lib/weekdayjs.min.js
[coveralls-badge]: https://coveralls.io/repos/ZiQiangWang/weekday.js/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/ZiQiangWang/weekdayjs## Install
```
npm i weekdayjs
```## Usage
Import the whole library, ~4kb bundle size.
```Js
import { rangeCount } from 'weekdayjs';
```or use the function as you need,
```js
import rangeCount from 'weekdayjs/lib/rangeCount';
```## API
### [isWeekday](src/isWeekday/index.js)
Check if the given date fall on a weekday.
**Params**
- `date` **{Date}**: The date to be checked.
- return **{Boolean}** The date is weekday**Example**
```js
isWeekday(new Date(2018, 5, 20))
// => true
```### [rangeCount](src/rangeCount/index.js)
Get weekday count between two dates.
**Params**
- `start` **{Date}**: The start date.
- `end` **{Date}**: The end date.
- return **{Number}** The count between start and end**Example**
```js
rangeCount(new Date(2018, 5, 20), new Date(2018, 5, 30))
// => 8
```### [rangeWeekdays](src/rangeWeekdays/index.js)
Get weekday list between given dates.
**Params**
- `start` **{Date}**: The start date.
- `end` **{Date}**: The end date.
- `fmt` **{String}**: Result format, return **Date** type if `fmt` is not defined.
- return **{Array}** Weekday list between given dates**Example**
```js
rangeWeekdays(new Date(2018, 5, 20), new Date(2018, 5, 25))
// => [
// new Date(2018, 5, 20),
// new Date(2018, 5, 21),
// new Date(2018, 5, 22),
// new Date(2018, 5, 25),
// ]
```### [recentWeekdays](src/recentWeekdays/index.js)
Get a certain amount of weekdays from given date.
**Params**
- `days` **{Number}**: Weekday count.
- `origin` **{Date}**: The original date, default today.
- `fmt` **{String}**: Result format, return **Date** type if `fmt` is not defined.
- return **{Array}** Recent weekday list**Example**
```js
recentWeekdays(3, new Date(2018, 5, 20))
// => [
// new Date(2018, 5, 20),
// new Date(2018, 5, 21),
// new Date(2018, 5, 22),
// ]
```### [distanceCount](src/distanceCount/index.js)
Get the number of weekday in the range of n days from given date.
**Params**
- `offset` **{Number}**: Days from original date.
- `origin` **{Date}**: The original date, default today.
- return **{Number}** The cound**Example**
```js
distanceCount(10, new Date(2018, 5, 20))
// => 8
```### [distanceWeekdays](src/distanceWeekdays/index.js)
Get the weekday list in the range of n days from given date.
**Params**
- `offset` **{Number}**: Days from original date.
- `origin` **{Date}**: The original date, default today.
- `fmt` **{String}**: Result format, return **Date** type if `fmt` is not defined.
- return **{Number}** The cound**Example**
```js
distanceWeekdays(5, new Date(2018, 5, 25))
// => [
// new Date(2018, 5, 20),
// new Date(2018, 5, 21),
// new Date(2018, 5, 22),
// new Date(2018, 5, 25),
// ]
```### [format](src/format/index.js)
Format date to given mask.
**Params**
- `date` **{Date}**: Date to format.
- `maks` **{String}**: Format mask.
- `utc` **{Boolean}**: Use utc or not.
- return **{String}** Formated date.**Example**
```js
format(new Date(2018, 5, 20), 'yyyy/mm/dd')
// => 2018/06/20
```### License
Copyright © 2018, [ZiQiangWang](https://github.com/ZiQiangWang).
Released under the [MIT License](LICENSE).