@ultirequiem/leap-year 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +14 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +23 -0
- package/package.json +1 -1
- package/readme.md +7 -9
package/lib/index.d.ts
CHANGED
|
@@ -19,4 +19,18 @@ export declare function isLeapYear(year?: Date | string | number, returnValue?:
|
|
|
19
19
|
year: number;
|
|
20
20
|
result: boolean;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* List every leap year in a range, both ends included.
|
|
24
|
+
*
|
|
25
|
+
* @param min - First year to check, defaults to `0`.
|
|
26
|
+
* @param max - Last year to check, defaults to the current year.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```javascript
|
|
30
|
+
* import { leapYearsInRange } from "@ultirequiem/leap-year";
|
|
31
|
+
*
|
|
32
|
+
* leapYearsInRange(2000, 2020); //=> [2000, 2004, 2008, 2012, 2016, 2020]
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function leapYearsInRange(min?: Date | string | number, max?: Date | string | number): number[];
|
|
22
36
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACnE,wBAAgB,UAAU,CACxB,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,WAAW,CAAC,EAAE,OAAO,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACnE,wBAAgB,UAAU,CACxB,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,WAAW,CAAC,EAAE,OAAO,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAYrC;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,GAAE,IAAI,GAAG,MAAM,GAAG,MAAU,EAC/B,GAAG,GAAE,IAAI,GAAG,MAAM,GAAG,MAAmB,GACvC,MAAM,EAAE,CAWV"}
|
package/lib/index.js
CHANGED
|
@@ -4,3 +4,26 @@ export function isLeapYear(year = new Date(), returnValue = false) {
|
|
|
4
4
|
const result = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
5
5
|
return returnValue ? { result, year } : result;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* List every leap year in a range, both ends included.
|
|
9
|
+
*
|
|
10
|
+
* @param min - First year to check, defaults to `0`.
|
|
11
|
+
* @param max - Last year to check, defaults to the current year.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* import { leapYearsInRange } from "@ultirequiem/leap-year";
|
|
16
|
+
*
|
|
17
|
+
* leapYearsInRange(2000, 2020); //=> [2000, 2004, 2008, 2012, 2016, 2020]
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function leapYearsInRange(min = 0, max = new Date()) {
|
|
21
|
+
const maxYear = parseDateLike(max);
|
|
22
|
+
const years = [];
|
|
23
|
+
for (let year = parseDateLike(min); year <= maxYear; year++) {
|
|
24
|
+
if (isLeapYear(year)) {
|
|
25
|
+
years.push(year);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return years;
|
|
29
|
+
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# leap-year
|
|
2
2
|
|
|
3
|
-
Check
|
|
3
|
+
Check whether a year is a leap year.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ultirequiem/leap-year)
|
|
6
6
|
[](https://www.npmjs.com/package/@ultirequiem/leap-year)
|
|
7
7
|
[](https://github.com/UltiRequiem/leap-year/actions/workflows/ci.yaml)
|
|
8
8
|
[](https://codecov.io/gh/UltiRequiem/leap-year)
|
|
9
9
|
|
|
10
|
+
Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year),
|
|
10
11
|
that's a calendar year that contains an additional day added to keep the
|
|
11
12
|
calendar year synchronized with the astronomical year or seasonal year.
|
|
12
13
|
|
|
@@ -25,16 +26,13 @@ isLeapYear(new Date(2016, 1, 1)); //=> true
|
|
|
25
26
|
isLeapYear("13 December 400 00:07:00 GMT", true); //=> { year: 400, result: true }
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- [leap_year_utils](https://github.com/UltiRequiem/leap_year_utils): Utilities
|
|
31
|
-
around this package.
|
|
29
|
+
List the leap years in a range (both ends included):
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
```javascript
|
|
32
|
+
import { leapYearsInRange } from "@ultirequiem/leap-year";
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
leapYearsInRange(2000, 2020); //=> [2000, 2004, 2008, 2012, 2016, 2020]
|
|
35
|
+
```
|
|
38
36
|
|
|
39
37
|
## Support
|
|
40
38
|
|