@ultirequiem/leap-year 2.0.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Eliaz Bobadilla <eliaz.bobadilla@gmail.com> (https://ultirequiem.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # leap-year
2
+
3
+ [![CI](https://github.com/UltiRequiem/leap-year/actions/workflows/ci.yaml/badge.svg)](https://github.com/UltiRequiem/leap-year/actions/workflows/ci.yaml)
4
+ [![codecov](https://codecov.io/gh/ultirequiem/leap-year/branch/main/graph/badge.svg)](https://codecov.io/gh/ultirequiem/leap-year)
5
+ [![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/leap_year/mod.ts)
6
+
7
+ ![Custom badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fdep-count%2Fx%2Fleap_year%2Fmod.ts)
8
+ ![Custom badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fupdates%2Fx%2Fleap_year%2Fmod.ts)
9
+ [![Custom badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fleap_year%2Fmod.ts)](https://deno.land/x/leap_year)
10
+
11
+ Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year).
12
+
13
+ ## Usage
14
+
15
+ ### [Deno 🚀](https://deno.land/x/leap_year)
16
+
17
+ ```javascript
18
+ import { isLeapYear } from "https://deno.land/x/leap_year/mod.ts";
19
+
20
+ isLeapYear(2014); //=> false
21
+ isLeapYear(2016); //=> true
22
+ isLeapYear("6 October 2006 00:07:00 GMT"); //=> false
23
+ isLeapYear("2000"); //=> false
24
+ isLeapYear(new Date(2016, 1, 1)); //=> true
25
+ ```
26
+
27
+ ### [Node.js 🐢](https://www.npmjs.com/package/@ultirequiem/leap-year)
28
+
29
+ ```typescript
30
+ import { isLeapYear } from "@ultirequiem/leap-year";
31
+ ```
32
+
33
+ ### [Browser 🕸](https://developer.mozilla.org/en-US/docs/Glossary/Browser)
34
+
35
+ You can use any [CDN](https://en.wikipedia.org/wiki/Content_delivery_network)
36
+ that you like.
37
+
38
+ As an example, for
39
+ [type module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
40
+ 👇
41
+
42
+ - [SkyPack](https://cdn.skypack.dev/@ultirequiem/leap-year)
43
+
44
+ Or for a plain
45
+ [script tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) 🦔
46
+
47
+ - [jsdelivr](https://cdn.jsdelivr.net/npm/@ultirequiem/leap-year)
48
+
49
+ The API is the same on all this platforms.
50
+
51
+ ## API
52
+
53
+ [Autogenerated Documentation](https://doc.deno.land/https://deno.land/x/leap_year/mod.ts)
54
+ 🚀
55
+
56
+ ## Support
57
+
58
+ Open an Issue, I will check it a soon as possible 👀
59
+
60
+ If you want to hurry me up a bit
61
+ [send me a tweet](https://twitter.com/intent/tweet?text=%40UltiRequiem%20) 😆
62
+
63
+ Consider [supporting me on Patreon](https://patreon.com/UltiRequiem) if you like
64
+ my work 🚀
65
+
66
+ Don't forget to start the repo ⭐
67
+
68
+ ## Licence
69
+
70
+ Licensed under the MIT License.
package/esm/mod.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year).
3
+ *
4
+ * @param year - Default: `new Date()`.
5
+ *
6
+ * @example
7
+ * ```javascript
8
+ * import { isLeapYear } from "https://deno.land/x/leap_year/mod.ts";
9
+ *
10
+ * isLeapYear(2014); //=> false
11
+ * isLeapYear(2016); //=> true
12
+ * isLeapYear("6 October 2006 00:07:00 GMT") //=> false
13
+ * isLeapYear("200"); //=> false
14
+ * isLeapYear(new Date(2016, 1, 1)); //=> true
15
+ * ```
16
+ */
17
+ export function isLeapYear(year = new Date()) {
18
+ year = internalParse(year);
19
+ return (year % 4 === 0 && year % 100 !== 0) ?? year % 400 === 0;
20
+ }
21
+ export function generateLeapYear(config) {
22
+ const { min = 0, max = new Date() } = config;
23
+ const maxYear = internalParse(max);
24
+ const leapYears = [];
25
+ for (let year = min; year <= maxYear; year++) {
26
+ if (isLeapYear(year)) {
27
+ leapYears.push(year);
28
+ }
29
+ }
30
+ return leapYears;
31
+ }
32
+ function internalParse(date) {
33
+ if (typeof date === "string") {
34
+ date = new Date(date);
35
+ }
36
+ if (!(date instanceof Date) && typeof date !== "number") {
37
+ throw new TypeError(`Expected "year" type to be "Date" | "number" | "string" and got ${typeof date}.`);
38
+ }
39
+ return date instanceof Date ? date.getUTCFullYear() : date;
40
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "module": "./esm/mod.js",
3
+ "main": "./script/mod.js",
4
+ "types": "./types/mod.d.ts",
5
+ "name": "@ultirequiem/leap-year",
6
+ "description": "Check if a year is leap.",
7
+ "version": "2.0.0",
8
+ "license": "MIT",
9
+ "funding": {
10
+ "type": "patreon",
11
+ "url": "https://www.patreon.com/ultirequiem"
12
+ },
13
+ "repository": "github:ultirequiem/@ultirequiem/leap-year",
14
+ "homepage": "https://leap-year.js.org",
15
+ "bugs": {
16
+ "url": "https://github.com/ultirequiem/@ultirequiem/leap-year/issues",
17
+ "email": "eliaz.bobadilladev@gmail.com"
18
+ },
19
+ "keywords": [
20
+ "leap",
21
+ "year",
22
+ "date"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "import": "./esm/mod.js",
27
+ "require": "./script/mod.js",
28
+ "types": "./types/mod.d.ts"
29
+ }
30
+ },
31
+ "scripts": {
32
+ "test": "node test_runner.js"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {
36
+ "@types/node": "16.11.26",
37
+ "chalk": "4.1.2",
38
+ "@deno/shim-deno": "~0.4.3"
39
+ }
40
+ }
package/script/mod.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateLeapYear = exports.isLeapYear = void 0;
4
+ /**
5
+ * Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year).
6
+ *
7
+ * @param year - Default: `new Date()`.
8
+ *
9
+ * @example
10
+ * ```javascript
11
+ * import { isLeapYear } from "https://deno.land/x/leap_year/mod.ts";
12
+ *
13
+ * isLeapYear(2014); //=> false
14
+ * isLeapYear(2016); //=> true
15
+ * isLeapYear("6 October 2006 00:07:00 GMT") //=> false
16
+ * isLeapYear("200"); //=> false
17
+ * isLeapYear(new Date(2016, 1, 1)); //=> true
18
+ * ```
19
+ */
20
+ function isLeapYear(year = new Date()) {
21
+ year = internalParse(year);
22
+ return (year % 4 === 0 && year % 100 !== 0) ?? year % 400 === 0;
23
+ }
24
+ exports.isLeapYear = isLeapYear;
25
+ function generateLeapYear(config) {
26
+ const { min = 0, max = new Date() } = config;
27
+ const maxYear = internalParse(max);
28
+ const leapYears = [];
29
+ for (let year = min; year <= maxYear; year++) {
30
+ if (isLeapYear(year)) {
31
+ leapYears.push(year);
32
+ }
33
+ }
34
+ return leapYears;
35
+ }
36
+ exports.generateLeapYear = generateLeapYear;
37
+ function internalParse(date) {
38
+ if (typeof date === "string") {
39
+ date = new Date(date);
40
+ }
41
+ if (!(date instanceof Date) && typeof date !== "number") {
42
+ throw new TypeError(`Expected "year" type to be "Date" | "number" | "string" and got ${typeof date}.`);
43
+ }
44
+ return date instanceof Date ? date.getUTCFullYear() : date;
45
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
package/types/mod.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year).
3
+ *
4
+ * @param year - Default: `new Date()`.
5
+ *
6
+ * @example
7
+ * ```javascript
8
+ * import { isLeapYear } from "https://deno.land/x/leap_year/mod.ts";
9
+ *
10
+ * isLeapYear(2014); //=> false
11
+ * isLeapYear(2016); //=> true
12
+ * isLeapYear("6 October 2006 00:07:00 GMT") //=> false
13
+ * isLeapYear("200"); //=> false
14
+ * isLeapYear(new Date(2016, 1, 1)); //=> true
15
+ * ```
16
+ */
17
+ export declare function isLeapYear(year?: DateLike): boolean;
18
+ export declare function generateLeapYear(config: {
19
+ min?: number;
20
+ max?: DateLike;
21
+ }): number[];
22
+ export declare type DateLike = Date | number | string;