@ultirequiem/leap-year 2.1.0 → 3.0.1
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/{types/mod.d.ts → lib/index.d.ts} +2 -2
- package/lib/index.d.ts.map +1 -0
- package/{esm/mod.js → lib/index.js} +1 -2
- package/lib/parse-date-like.d.ts +11 -0
- package/lib/parse-date-like.d.ts.map +1 -0
- package/lib/parse-date-like.js +26 -0
- package/package.json +44 -33
- package/readme.md +55 -0
- package/README.md +0 -109
- package/esm/_dnt.polyfills.js +0 -15
- package/esm/_dnt.shims.js +0 -62
- package/esm/deps/deno.land/std@0.128.0/_util/assert.js +0 -14
- package/esm/deps/deno.land/std@0.128.0/flags/mod.js +0 -256
- package/esm/deps/deno.land/x/parse_datelike@0.0.1/mod.js +0 -9
- package/esm/leap-year.js +0 -17
- package/esm/package.json +0 -3
- package/script/_dnt.polyfills.js +0 -16
- package/script/_dnt.shims.js +0 -66
- package/script/deps/deno.land/std@0.128.0/_util/assert.js +0 -19
- package/script/deps/deno.land/std@0.128.0/flags/mod.js +0 -260
- package/script/deps/deno.land/x/parse_datelike@0.0.1/mod.js +0 -13
- package/script/leap-year.js +0 -42
- package/script/mod.js +0 -11
- package/script/package.json +0 -3
- package/types/_dnt.polyfills.d.ts +0 -11
- package/types/_dnt.shims.d.ts +0 -5
- package/types/deps/deno.land/std@0.128.0/_util/assert.d.ts +0 -5
- package/types/deps/deno.land/std@0.128.0/flags/mod.d.ts +0 -50
- package/types/deps/deno.land/x/parse_datelike@0.0.1/mod.d.ts +0 -2
- package/types/leap-year.d.ts +0 -2
- /package/{LICENSE → license} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./_dnt.polyfills.js";
|
|
2
1
|
/**
|
|
3
2
|
* Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year).
|
|
4
3
|
*
|
|
@@ -6,7 +5,7 @@ import "./_dnt.polyfills.js";
|
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
8
7
|
* ```javascript
|
|
9
|
-
* import { isLeapYear } from "
|
|
8
|
+
* import { isLeapYear } from "@ultirequiem/leap-year";
|
|
10
9
|
*
|
|
11
10
|
* isLeapYear(2014); //=> false
|
|
12
11
|
* isLeapYear(2016); //=> true
|
|
@@ -20,3 +19,4 @@ export declare function isLeapYear(year?: Date | string | number, returnValue?:
|
|
|
20
19
|
year: number;
|
|
21
20
|
result: boolean;
|
|
22
21
|
};
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,5 +1,4 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { parseDateLike } from "./deps/deno.land/x/parse_datelike@0.0.1/mod.js";
|
|
1
|
+
import { parseDateLike } from "./parse-date-like.js";
|
|
3
2
|
export function isLeapYear(year = new Date(), returnValue = false) {
|
|
4
3
|
year = parseDateLike(year);
|
|
5
4
|
const result = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the (UTC) year out of anything date-like.
|
|
3
|
+
*
|
|
4
|
+
* @param value - A `Date`, a year as number or string, or a date string.
|
|
5
|
+
*
|
|
6
|
+
* @throws {@link TypeError}
|
|
7
|
+
*
|
|
8
|
+
* Thrown if the value cannot be turned into a year.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseDateLike(value: Date | string | number): number;
|
|
11
|
+
//# sourceMappingURL=parse-date-like.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-date-like.d.ts","sourceRoot":"","sources":["../src/parse-date-like.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAsBnE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the (UTC) year out of anything date-like.
|
|
3
|
+
*
|
|
4
|
+
* @param value - A `Date`, a year as number or string, or a date string.
|
|
5
|
+
*
|
|
6
|
+
* @throws {@link TypeError}
|
|
7
|
+
*
|
|
8
|
+
* Thrown if the value cannot be turned into a year.
|
|
9
|
+
*/
|
|
10
|
+
export function parseDateLike(value) {
|
|
11
|
+
if (value instanceof Date) {
|
|
12
|
+
return value.getUTCFullYear();
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === "number") {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
const year = Number(value);
|
|
18
|
+
if (value.trim() !== "" && Number.isInteger(year)) {
|
|
19
|
+
return year;
|
|
20
|
+
}
|
|
21
|
+
const date = new Date(value);
|
|
22
|
+
if (Number.isNaN(date.getTime())) {
|
|
23
|
+
throw new TypeError(`Could not get a year out of "${value}".`);
|
|
24
|
+
}
|
|
25
|
+
return date.getUTCFullYear();
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
"module": "./esm/mod.js",
|
|
3
|
-
"main": "./script/mod.js",
|
|
4
|
-
"types": "./types/mod.d.ts",
|
|
5
|
-
"bin": {
|
|
6
|
-
"leap-year": "./esm/leap-year.js"
|
|
7
|
-
},
|
|
8
2
|
"name": "@ultirequiem/leap-year",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Check whether a year is a leap year.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.js"
|
|
12
|
+
}
|
|
15
13
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
14
|
+
"files": [
|
|
15
|
+
"lib/**/*"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20"
|
|
21
19
|
},
|
|
22
20
|
"keywords": [
|
|
23
|
-
"leap",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"leap-year",
|
|
22
|
+
"date",
|
|
23
|
+
"calendar",
|
|
24
|
+
"esm",
|
|
25
|
+
"typescript"
|
|
26
26
|
],
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"homepage": "https://leap-year.js.org",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/UltiRequiem/leap-year.git"
|
|
33
32
|
},
|
|
34
33
|
"scripts": {
|
|
35
|
-
"
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"lint": "eslint 'src/**/*.ts' && prettier --check 'src/**/*.ts'",
|
|
36
|
+
"fmt": "prettier --write 'src/**/*.ts'",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:coverage": "vitest run --coverage"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^26.6.5",
|
|
42
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
43
|
+
"eslint": "^10.13.0",
|
|
44
|
+
"eslint-plugin-tsdoc": "^0.5.4",
|
|
45
|
+
"eslint-plugin-unicorn": "^78.0.0",
|
|
46
|
+
"prettier": "^3.9.10",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"typescript-eslint": "^8.72.0",
|
|
49
|
+
"vitest": "^5.0.5"
|
|
36
50
|
},
|
|
37
51
|
"dependencies": {
|
|
38
|
-
"@
|
|
52
|
+
"@ultirequiem/leap-year": "^2.1.0"
|
|
39
53
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"chalk": "4.1.2"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
54
|
+
"packageManager": "pnpm@12.6.0"
|
|
55
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# leap-year
|
|
2
|
+
|
|
3
|
+
Check if a year is a [leap year](https://en.wikipedia.org/wiki/Leap_year),
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@ultirequiem/leap-year)
|
|
6
|
+
[](https://www.npmjs.com/package/@ultirequiem/leap-year)
|
|
7
|
+
[](https://github.com/UltiRequiem/leap-year/actions/workflows/ci.yaml)
|
|
8
|
+
[](https://codecov.io/gh/UltiRequiem/leap-year)
|
|
9
|
+
|
|
10
|
+
that's a calendar year that contains an additional day added to keep the
|
|
11
|
+
calendar year synchronized with the astronomical year or seasonal year.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
ESM only, types included: the same import works in Node.js, Bun and browsers.
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { isLeapYear } from "@ultirequiem/leap-year";
|
|
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
|
+
isLeapYear("13 December 400 00:07:00 GMT", true); //=> { year: 400, result: true }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Related
|
|
29
|
+
|
|
30
|
+
- [leap_year_utils](https://github.com/UltiRequiem/leap_year_utils): Utilities
|
|
31
|
+
around this package.
|
|
32
|
+
|
|
33
|
+
- [parse_datelike](https://github.com/UltiRequiem/parse_datelike): Parse a
|
|
34
|
+
number/string/date to a number/string/date.
|
|
35
|
+
|
|
36
|
+
- [leap-year-api](https://github.com/UltiRequiem/leap-year-api): A REST API to
|
|
37
|
+
know if a year is leap or not.
|
|
38
|
+
|
|
39
|
+
## Support
|
|
40
|
+
|
|
41
|
+
Open an Issue, I will check it as soon as possible 👀
|
|
42
|
+
|
|
43
|
+
If you want to hurry me up a bit
|
|
44
|
+
[send me a tweet](https://twitter.com/UltiRequiem) 😆
|
|
45
|
+
|
|
46
|
+
Don't forget to star the repo ⭐
|
|
47
|
+
|
|
48
|
+
## Versioning
|
|
49
|
+
|
|
50
|
+
We use [Semantic Versioning](http://semver.org). For the versions available, see
|
|
51
|
+
the [tags](https://github.com/UltiRequiem/leap-year/tags) 🏷️
|
|
52
|
+
|
|
53
|
+
## Licence
|
|
54
|
+
|
|
55
|
+
Licensed under the MIT License 📄
|
package/README.md
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# leap-year
|
|
2
|
-
|
|
3
|
-
[](https://github.com/UltiRequiem/leap-year/actions/workflows/ci.yaml)
|
|
4
|
-
[](https://codecov.io/gh/ultirequiem/leap-year)
|
|
5
|
-
[](https://doc.deno.land/https/deno.land/x/leap_year/mod.ts)
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-

|
|
9
|
-
[](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
|
-
isLeapYear("13 December 400 00:07:00 GMT", true); //=> { year: 400, result: true }
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### [Node.js 🐢](https://www.npmjs.com/package/@ultirequiem/leap-year)
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
31
|
-
import { isLeapYear } from "@ultirequiem/leap-year";
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### [Browser 🕸](https://developer.mozilla.org/en-US/docs/Glossary/Browser)
|
|
35
|
-
|
|
36
|
-
You can use any [CDN](https://en.wikipedia.org/wiki/Content_delivery_network)
|
|
37
|
-
that you like.
|
|
38
|
-
|
|
39
|
-
Eg. [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
40
|
-
▶ [SkyPack](https://cdn.skypack.dev/@ultirequiem/leap-year) _/_
|
|
41
|
-
[script tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) ▶
|
|
42
|
-
[JSDelivr](https://cdn.jsdelivr.net/npm/@ultirequiem/leap-year).
|
|
43
|
-
|
|
44
|
-
The API is the same on all this platforms.
|
|
45
|
-
|
|
46
|
-
## API
|
|
47
|
-
|
|
48
|
-
[Autogenerated Documentation](https://doc.deno.land/https://deno.land/x/leap_year/mod.ts)
|
|
49
|
-
🚀
|
|
50
|
-
|
|
51
|
-
## CLI Tool
|
|
52
|
-
|
|
53
|
-
Was done mainly as usage example.
|
|
54
|
-
|
|
55
|
-
### Install
|
|
56
|
-
|
|
57
|
-
- Node.js 🦍
|
|
58
|
-
|
|
59
|
-
```sh
|
|
60
|
-
npm install -g @ultirequiem/leap-year
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
- Deno 🦕
|
|
64
|
-
|
|
65
|
-
```sh
|
|
66
|
-
deno install https://deno.land/x/leap_year/leap-year.ts
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Usage
|
|
70
|
-
|
|
71
|
-
```sh
|
|
72
|
-
leap-year "13 October 2020 00:07:00 GMT" 400 345
|
|
73
|
-
true
|
|
74
|
-
true
|
|
75
|
-
false
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Or with the verbose flag 👇
|
|
79
|
-
|
|
80
|
-
```sh
|
|
81
|
-
leap-year "13 October 2020 00:07:00 GMT" 400 345 --verbose # -v
|
|
82
|
-
2020 is a leap year.
|
|
83
|
-
400 is a leap year.
|
|
84
|
-
345 is not a leap year.
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Related
|
|
88
|
-
|
|
89
|
-
- [leap_year_utils](https://github.com/UltiRequiem/leap_year_utils): Utilities
|
|
90
|
-
around this package
|
|
91
|
-
|
|
92
|
-
- [parse_datelike](https://github.com/UltiRequiem/parse_datelike): Parse a
|
|
93
|
-
number/string/date to a number/string/date
|
|
94
|
-
|
|
95
|
-
## Support
|
|
96
|
-
|
|
97
|
-
Open an Issue, I will check it a soon as possible 👀
|
|
98
|
-
|
|
99
|
-
If you want to hurry me up a bit
|
|
100
|
-
[send me a tweet](https://twitter.com/intent/tweet?text=%40UltiRequiem%20) 😆
|
|
101
|
-
|
|
102
|
-
Consider [supporting me on Patreon](https://patreon.com/UltiRequiem) if you like
|
|
103
|
-
my work 🚀
|
|
104
|
-
|
|
105
|
-
Don't forget to start the repo ⭐
|
|
106
|
-
|
|
107
|
-
## Licence
|
|
108
|
-
|
|
109
|
-
Licensed under the MIT License.
|
package/esm/_dnt.polyfills.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
-
if (!Object.hasOwn) {
|
|
3
|
-
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
-
value: function (object, property) {
|
|
5
|
-
if (object == null) {
|
|
6
|
-
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
-
}
|
|
8
|
-
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
-
},
|
|
10
|
-
configurable: true,
|
|
11
|
-
enumerable: false,
|
|
12
|
-
writable: true,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/esm/_dnt.shims.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Deno } from "@deno/shim-deno";
|
|
2
|
-
export { Deno } from "@deno/shim-deno";
|
|
3
|
-
const dntGlobals = {
|
|
4
|
-
Deno,
|
|
5
|
-
};
|
|
6
|
-
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
7
|
-
// deno-lint-ignore ban-types
|
|
8
|
-
function createMergeProxy(baseObj, extObj) {
|
|
9
|
-
return new Proxy(baseObj, {
|
|
10
|
-
get(_target, prop, _receiver) {
|
|
11
|
-
if (prop in extObj) {
|
|
12
|
-
return extObj[prop];
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return baseObj[prop];
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
set(_target, prop, value) {
|
|
19
|
-
if (prop in extObj) {
|
|
20
|
-
delete extObj[prop];
|
|
21
|
-
}
|
|
22
|
-
baseObj[prop] = value;
|
|
23
|
-
return true;
|
|
24
|
-
},
|
|
25
|
-
deleteProperty(_target, prop) {
|
|
26
|
-
let success = false;
|
|
27
|
-
if (prop in extObj) {
|
|
28
|
-
delete extObj[prop];
|
|
29
|
-
success = true;
|
|
30
|
-
}
|
|
31
|
-
if (prop in baseObj) {
|
|
32
|
-
delete baseObj[prop];
|
|
33
|
-
success = true;
|
|
34
|
-
}
|
|
35
|
-
return success;
|
|
36
|
-
},
|
|
37
|
-
ownKeys(_target) {
|
|
38
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
39
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
40
|
-
const extKeysSet = new Set(extKeys);
|
|
41
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
42
|
-
},
|
|
43
|
-
defineProperty(_target, prop, desc) {
|
|
44
|
-
if (prop in extObj) {
|
|
45
|
-
delete extObj[prop];
|
|
46
|
-
}
|
|
47
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
48
|
-
return true;
|
|
49
|
-
},
|
|
50
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
51
|
-
if (prop in extObj) {
|
|
52
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
has(_target, prop) {
|
|
59
|
-
return prop in extObj || prop in baseObj;
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
export class DenoStdInternalError extends Error {
|
|
4
|
-
constructor(message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "DenoStdInternalError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/** Make an assertion, if not `true`, then throw. */
|
|
10
|
-
export function assert(expr, msg = "") {
|
|
11
|
-
if (!expr) {
|
|
12
|
-
throw new DenoStdInternalError(msg);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
import { assert } from "../_util/assert.js";
|
|
4
|
-
const { hasOwn } = Object;
|
|
5
|
-
function get(obj, key) {
|
|
6
|
-
if (hasOwn(obj, key)) {
|
|
7
|
-
return obj[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function getForce(obj, key) {
|
|
11
|
-
const v = get(obj, key);
|
|
12
|
-
assert(v != null);
|
|
13
|
-
return v;
|
|
14
|
-
}
|
|
15
|
-
function isNumber(x) {
|
|
16
|
-
if (typeof x === "number")
|
|
17
|
-
return true;
|
|
18
|
-
if (/^0x[0-9a-f]+$/i.test(String(x)))
|
|
19
|
-
return true;
|
|
20
|
-
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x));
|
|
21
|
-
}
|
|
22
|
-
function hasKey(obj, keys) {
|
|
23
|
-
let o = obj;
|
|
24
|
-
keys.slice(0, -1).forEach((key) => {
|
|
25
|
-
o = (get(o, key) ?? {});
|
|
26
|
-
});
|
|
27
|
-
const key = keys[keys.length - 1];
|
|
28
|
-
return key in o;
|
|
29
|
-
}
|
|
30
|
-
/** Take a set of command line arguments, with an optional set of options, and
|
|
31
|
-
* return an object representation of those argument.
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { parse } from "./mod.ts";
|
|
35
|
-
* const parsedArgs = parse(Deno.args);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
|
|
39
|
-
const flags = {
|
|
40
|
-
bools: {},
|
|
41
|
-
strings: {},
|
|
42
|
-
unknownFn: unknown,
|
|
43
|
-
allBools: false,
|
|
44
|
-
};
|
|
45
|
-
if (boolean !== undefined) {
|
|
46
|
-
if (typeof boolean === "boolean") {
|
|
47
|
-
flags.allBools = !!boolean;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
|
|
51
|
-
for (const key of booleanArgs.filter(Boolean)) {
|
|
52
|
-
flags.bools[key] = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const aliases = {};
|
|
57
|
-
if (alias !== undefined) {
|
|
58
|
-
for (const key in alias) {
|
|
59
|
-
const val = getForce(alias, key);
|
|
60
|
-
if (typeof val === "string") {
|
|
61
|
-
aliases[key] = [val];
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
aliases[key] = val;
|
|
65
|
-
}
|
|
66
|
-
for (const alias of getForce(aliases, key)) {
|
|
67
|
-
aliases[alias] = [key].concat(aliases[key].filter((y) => alias !== y));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (string !== undefined) {
|
|
72
|
-
const stringArgs = typeof string === "string" ? [string] : string;
|
|
73
|
-
for (const key of stringArgs.filter(Boolean)) {
|
|
74
|
-
flags.strings[key] = true;
|
|
75
|
-
const alias = get(aliases, key);
|
|
76
|
-
if (alias) {
|
|
77
|
-
for (const al of alias) {
|
|
78
|
-
flags.strings[al] = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const argv = { _: [] };
|
|
84
|
-
function argDefined(key, arg) {
|
|
85
|
-
return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
86
|
-
get(flags.bools, key) ||
|
|
87
|
-
!!get(flags.strings, key) ||
|
|
88
|
-
!!get(aliases, key));
|
|
89
|
-
}
|
|
90
|
-
function setKey(obj, keys, value) {
|
|
91
|
-
let o = obj;
|
|
92
|
-
keys.slice(0, -1).forEach(function (key) {
|
|
93
|
-
if (get(o, key) === undefined) {
|
|
94
|
-
o[key] = {};
|
|
95
|
-
}
|
|
96
|
-
o = get(o, key);
|
|
97
|
-
});
|
|
98
|
-
const key = keys[keys.length - 1];
|
|
99
|
-
if (get(o, key) === undefined ||
|
|
100
|
-
get(flags.bools, key) ||
|
|
101
|
-
typeof get(o, key) === "boolean") {
|
|
102
|
-
o[key] = value;
|
|
103
|
-
}
|
|
104
|
-
else if (Array.isArray(get(o, key))) {
|
|
105
|
-
o[key].push(value);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
o[key] = [get(o, key), value];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function setArg(key, val, arg = undefined) {
|
|
112
|
-
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
113
|
-
if (flags.unknownFn(arg, key, val) === false)
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
|
|
117
|
-
setKey(argv, key.split("."), value);
|
|
118
|
-
const alias = get(aliases, key);
|
|
119
|
-
if (alias) {
|
|
120
|
-
for (const x of alias) {
|
|
121
|
-
setKey(argv, x.split("."), value);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function aliasIsBoolean(key) {
|
|
126
|
-
return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
|
|
127
|
-
}
|
|
128
|
-
for (const key of Object.keys(flags.bools)) {
|
|
129
|
-
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
130
|
-
}
|
|
131
|
-
let notFlags = [];
|
|
132
|
-
// all args after "--" are not parsed
|
|
133
|
-
if (args.includes("--")) {
|
|
134
|
-
notFlags = args.slice(args.indexOf("--") + 1);
|
|
135
|
-
args = args.slice(0, args.indexOf("--"));
|
|
136
|
-
}
|
|
137
|
-
for (let i = 0; i < args.length; i++) {
|
|
138
|
-
const arg = args[i];
|
|
139
|
-
if (/^--.+=/.test(arg)) {
|
|
140
|
-
const m = arg.match(/^--([^=]+)=(.*)$/s);
|
|
141
|
-
assert(m != null);
|
|
142
|
-
const [, key, value] = m;
|
|
143
|
-
if (flags.bools[key]) {
|
|
144
|
-
const booleanValue = value !== "false";
|
|
145
|
-
setArg(key, booleanValue, arg);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
setArg(key, value, arg);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else if (/^--no-.+/.test(arg)) {
|
|
152
|
-
const m = arg.match(/^--no-(.+)/);
|
|
153
|
-
assert(m != null);
|
|
154
|
-
setArg(m[1], false, arg);
|
|
155
|
-
}
|
|
156
|
-
else if (/^--.+/.test(arg)) {
|
|
157
|
-
const m = arg.match(/^--(.+)/);
|
|
158
|
-
assert(m != null);
|
|
159
|
-
const [, key] = m;
|
|
160
|
-
const next = args[i + 1];
|
|
161
|
-
if (next !== undefined &&
|
|
162
|
-
!/^-/.test(next) &&
|
|
163
|
-
!get(flags.bools, key) &&
|
|
164
|
-
!flags.allBools &&
|
|
165
|
-
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
166
|
-
setArg(key, next, arg);
|
|
167
|
-
i++;
|
|
168
|
-
}
|
|
169
|
-
else if (/^(true|false)$/.test(next)) {
|
|
170
|
-
setArg(key, next === "true", arg);
|
|
171
|
-
i++;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else if (/^-[^-]+/.test(arg)) {
|
|
178
|
-
const letters = arg.slice(1, -1).split("");
|
|
179
|
-
let broken = false;
|
|
180
|
-
for (let j = 0; j < letters.length; j++) {
|
|
181
|
-
const next = arg.slice(j + 2);
|
|
182
|
-
if (next === "-") {
|
|
183
|
-
setArg(letters[j], next, arg);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
|
187
|
-
setArg(letters[j], next.split(/=(.+)/)[1], arg);
|
|
188
|
-
broken = true;
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
if (/[A-Za-z]/.test(letters[j]) &&
|
|
192
|
-
/-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
|
193
|
-
setArg(letters[j], next, arg);
|
|
194
|
-
broken = true;
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
|
198
|
-
setArg(letters[j], arg.slice(j + 2), arg);
|
|
199
|
-
broken = true;
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
const [key] = arg.slice(-1);
|
|
207
|
-
if (!broken && key !== "-") {
|
|
208
|
-
if (args[i + 1] &&
|
|
209
|
-
!/^(-|--)[^-]/.test(args[i + 1]) &&
|
|
210
|
-
!get(flags.bools, key) &&
|
|
211
|
-
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
212
|
-
setArg(key, args[i + 1], arg);
|
|
213
|
-
i++;
|
|
214
|
-
}
|
|
215
|
-
else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
|
|
216
|
-
setArg(key, args[i + 1] === "true", arg);
|
|
217
|
-
i++;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
226
|
-
argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg));
|
|
227
|
-
}
|
|
228
|
-
if (stopEarly) {
|
|
229
|
-
argv._.push(...args.slice(i + 1));
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
for (const key of Object.keys(defaults)) {
|
|
235
|
-
if (!hasKey(argv, key.split("."))) {
|
|
236
|
-
setKey(argv, key.split("."), defaults[key]);
|
|
237
|
-
if (aliases[key]) {
|
|
238
|
-
for (const x of aliases[key]) {
|
|
239
|
-
setKey(argv, x.split("."), defaults[key]);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (doubleDash) {
|
|
245
|
-
argv["--"] = [];
|
|
246
|
-
for (const key of notFlags) {
|
|
247
|
-
argv["--"].push(key);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
for (const key of notFlags) {
|
|
252
|
-
argv._.push(key);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return argv;
|
|
256
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function parseDateLike(date) {
|
|
2
|
-
if (typeof date === "string") {
|
|
3
|
-
date = new Date(date);
|
|
4
|
-
}
|
|
5
|
-
if (!(date instanceof Date) && typeof date !== "number") {
|
|
6
|
-
throw new TypeError(`Expected "year" type to be "Date" | "number" | "string" and got ${typeof date}.`);
|
|
7
|
-
}
|
|
8
|
-
return date instanceof Date ? date.getUTCFullYear() : date;
|
|
9
|
-
}
|
package/esm/leap-year.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "./_dnt.polyfills.js";
|
|
3
|
-
import * as dntShim from "./_dnt.shims.js";
|
|
4
|
-
import { parse } from "./deps/deno.land/std@0.128.0/flags/mod.js";
|
|
5
|
-
import { isLeapYear } from "./mod.js";
|
|
6
|
-
const { _: years, verbose } = parse(dntShim.Deno.args, {
|
|
7
|
-
boolean: ["verbose"],
|
|
8
|
-
alias: { v: "verbose" },
|
|
9
|
-
});
|
|
10
|
-
for (const year of years) {
|
|
11
|
-
const { year: parsedYear, result } = isLeapYear(year, true);
|
|
12
|
-
if (verbose) {
|
|
13
|
-
console.log(`${parsedYear} is ${result ? "" : "not "}a leap year.`);
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
console.log(result);
|
|
17
|
-
}
|
package/esm/package.json
DELETED
package/script/_dnt.polyfills.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
4
|
-
if (!Object.hasOwn) {
|
|
5
|
-
Object.defineProperty(Object, "hasOwn", {
|
|
6
|
-
value: function (object, property) {
|
|
7
|
-
if (object == null) {
|
|
8
|
-
throw new TypeError("Cannot convert undefined or null to object");
|
|
9
|
-
}
|
|
10
|
-
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
11
|
-
},
|
|
12
|
-
configurable: true,
|
|
13
|
-
enumerable: false,
|
|
14
|
-
writable: true,
|
|
15
|
-
});
|
|
16
|
-
}
|
package/script/_dnt.shims.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dntGlobalThis = exports.Deno = void 0;
|
|
4
|
-
const shim_deno_1 = require("@deno/shim-deno");
|
|
5
|
-
var shim_deno_2 = require("@deno/shim-deno");
|
|
6
|
-
Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
|
|
7
|
-
const dntGlobals = {
|
|
8
|
-
Deno: shim_deno_1.Deno,
|
|
9
|
-
};
|
|
10
|
-
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
11
|
-
// deno-lint-ignore ban-types
|
|
12
|
-
function createMergeProxy(baseObj, extObj) {
|
|
13
|
-
return new Proxy(baseObj, {
|
|
14
|
-
get(_target, prop, _receiver) {
|
|
15
|
-
if (prop in extObj) {
|
|
16
|
-
return extObj[prop];
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return baseObj[prop];
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
set(_target, prop, value) {
|
|
23
|
-
if (prop in extObj) {
|
|
24
|
-
delete extObj[prop];
|
|
25
|
-
}
|
|
26
|
-
baseObj[prop] = value;
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
deleteProperty(_target, prop) {
|
|
30
|
-
let success = false;
|
|
31
|
-
if (prop in extObj) {
|
|
32
|
-
delete extObj[prop];
|
|
33
|
-
success = true;
|
|
34
|
-
}
|
|
35
|
-
if (prop in baseObj) {
|
|
36
|
-
delete baseObj[prop];
|
|
37
|
-
success = true;
|
|
38
|
-
}
|
|
39
|
-
return success;
|
|
40
|
-
},
|
|
41
|
-
ownKeys(_target) {
|
|
42
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
43
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
44
|
-
const extKeysSet = new Set(extKeys);
|
|
45
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
46
|
-
},
|
|
47
|
-
defineProperty(_target, prop, desc) {
|
|
48
|
-
if (prop in extObj) {
|
|
49
|
-
delete extObj[prop];
|
|
50
|
-
}
|
|
51
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
52
|
-
return true;
|
|
53
|
-
},
|
|
54
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
55
|
-
if (prop in extObj) {
|
|
56
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
has(_target, prop) {
|
|
63
|
-
return prop in extObj || prop in baseObj;
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.assert = exports.DenoStdInternalError = void 0;
|
|
6
|
-
class DenoStdInternalError extends Error {
|
|
7
|
-
constructor(message) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "DenoStdInternalError";
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.DenoStdInternalError = DenoStdInternalError;
|
|
13
|
-
/** Make an assertion, if not `true`, then throw. */
|
|
14
|
-
function assert(expr, msg = "") {
|
|
15
|
-
if (!expr) {
|
|
16
|
-
throw new DenoStdInternalError(msg);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.assert = assert;
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.parse = void 0;
|
|
6
|
-
const assert_js_1 = require("../_util/assert.js");
|
|
7
|
-
const { hasOwn } = Object;
|
|
8
|
-
function get(obj, key) {
|
|
9
|
-
if (hasOwn(obj, key)) {
|
|
10
|
-
return obj[key];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function getForce(obj, key) {
|
|
14
|
-
const v = get(obj, key);
|
|
15
|
-
(0, assert_js_1.assert)(v != null);
|
|
16
|
-
return v;
|
|
17
|
-
}
|
|
18
|
-
function isNumber(x) {
|
|
19
|
-
if (typeof x === "number")
|
|
20
|
-
return true;
|
|
21
|
-
if (/^0x[0-9a-f]+$/i.test(String(x)))
|
|
22
|
-
return true;
|
|
23
|
-
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x));
|
|
24
|
-
}
|
|
25
|
-
function hasKey(obj, keys) {
|
|
26
|
-
let o = obj;
|
|
27
|
-
keys.slice(0, -1).forEach((key) => {
|
|
28
|
-
o = (get(o, key) ?? {});
|
|
29
|
-
});
|
|
30
|
-
const key = keys[keys.length - 1];
|
|
31
|
-
return key in o;
|
|
32
|
-
}
|
|
33
|
-
/** Take a set of command line arguments, with an optional set of options, and
|
|
34
|
-
* return an object representation of those argument.
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { parse } from "./mod.ts";
|
|
38
|
-
* const parsedArgs = parse(Deno.args);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
|
|
42
|
-
const flags = {
|
|
43
|
-
bools: {},
|
|
44
|
-
strings: {},
|
|
45
|
-
unknownFn: unknown,
|
|
46
|
-
allBools: false,
|
|
47
|
-
};
|
|
48
|
-
if (boolean !== undefined) {
|
|
49
|
-
if (typeof boolean === "boolean") {
|
|
50
|
-
flags.allBools = !!boolean;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
|
|
54
|
-
for (const key of booleanArgs.filter(Boolean)) {
|
|
55
|
-
flags.bools[key] = true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const aliases = {};
|
|
60
|
-
if (alias !== undefined) {
|
|
61
|
-
for (const key in alias) {
|
|
62
|
-
const val = getForce(alias, key);
|
|
63
|
-
if (typeof val === "string") {
|
|
64
|
-
aliases[key] = [val];
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
aliases[key] = val;
|
|
68
|
-
}
|
|
69
|
-
for (const alias of getForce(aliases, key)) {
|
|
70
|
-
aliases[alias] = [key].concat(aliases[key].filter((y) => alias !== y));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (string !== undefined) {
|
|
75
|
-
const stringArgs = typeof string === "string" ? [string] : string;
|
|
76
|
-
for (const key of stringArgs.filter(Boolean)) {
|
|
77
|
-
flags.strings[key] = true;
|
|
78
|
-
const alias = get(aliases, key);
|
|
79
|
-
if (alias) {
|
|
80
|
-
for (const al of alias) {
|
|
81
|
-
flags.strings[al] = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const argv = { _: [] };
|
|
87
|
-
function argDefined(key, arg) {
|
|
88
|
-
return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
89
|
-
get(flags.bools, key) ||
|
|
90
|
-
!!get(flags.strings, key) ||
|
|
91
|
-
!!get(aliases, key));
|
|
92
|
-
}
|
|
93
|
-
function setKey(obj, keys, value) {
|
|
94
|
-
let o = obj;
|
|
95
|
-
keys.slice(0, -1).forEach(function (key) {
|
|
96
|
-
if (get(o, key) === undefined) {
|
|
97
|
-
o[key] = {};
|
|
98
|
-
}
|
|
99
|
-
o = get(o, key);
|
|
100
|
-
});
|
|
101
|
-
const key = keys[keys.length - 1];
|
|
102
|
-
if (get(o, key) === undefined ||
|
|
103
|
-
get(flags.bools, key) ||
|
|
104
|
-
typeof get(o, key) === "boolean") {
|
|
105
|
-
o[key] = value;
|
|
106
|
-
}
|
|
107
|
-
else if (Array.isArray(get(o, key))) {
|
|
108
|
-
o[key].push(value);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
o[key] = [get(o, key), value];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function setArg(key, val, arg = undefined) {
|
|
115
|
-
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
116
|
-
if (flags.unknownFn(arg, key, val) === false)
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
|
|
120
|
-
setKey(argv, key.split("."), value);
|
|
121
|
-
const alias = get(aliases, key);
|
|
122
|
-
if (alias) {
|
|
123
|
-
for (const x of alias) {
|
|
124
|
-
setKey(argv, x.split("."), value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function aliasIsBoolean(key) {
|
|
129
|
-
return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
|
|
130
|
-
}
|
|
131
|
-
for (const key of Object.keys(flags.bools)) {
|
|
132
|
-
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
133
|
-
}
|
|
134
|
-
let notFlags = [];
|
|
135
|
-
// all args after "--" are not parsed
|
|
136
|
-
if (args.includes("--")) {
|
|
137
|
-
notFlags = args.slice(args.indexOf("--") + 1);
|
|
138
|
-
args = args.slice(0, args.indexOf("--"));
|
|
139
|
-
}
|
|
140
|
-
for (let i = 0; i < args.length; i++) {
|
|
141
|
-
const arg = args[i];
|
|
142
|
-
if (/^--.+=/.test(arg)) {
|
|
143
|
-
const m = arg.match(/^--([^=]+)=(.*)$/s);
|
|
144
|
-
(0, assert_js_1.assert)(m != null);
|
|
145
|
-
const [, key, value] = m;
|
|
146
|
-
if (flags.bools[key]) {
|
|
147
|
-
const booleanValue = value !== "false";
|
|
148
|
-
setArg(key, booleanValue, arg);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
setArg(key, value, arg);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (/^--no-.+/.test(arg)) {
|
|
155
|
-
const m = arg.match(/^--no-(.+)/);
|
|
156
|
-
(0, assert_js_1.assert)(m != null);
|
|
157
|
-
setArg(m[1], false, arg);
|
|
158
|
-
}
|
|
159
|
-
else if (/^--.+/.test(arg)) {
|
|
160
|
-
const m = arg.match(/^--(.+)/);
|
|
161
|
-
(0, assert_js_1.assert)(m != null);
|
|
162
|
-
const [, key] = m;
|
|
163
|
-
const next = args[i + 1];
|
|
164
|
-
if (next !== undefined &&
|
|
165
|
-
!/^-/.test(next) &&
|
|
166
|
-
!get(flags.bools, key) &&
|
|
167
|
-
!flags.allBools &&
|
|
168
|
-
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
169
|
-
setArg(key, next, arg);
|
|
170
|
-
i++;
|
|
171
|
-
}
|
|
172
|
-
else if (/^(true|false)$/.test(next)) {
|
|
173
|
-
setArg(key, next === "true", arg);
|
|
174
|
-
i++;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
else if (/^-[^-]+/.test(arg)) {
|
|
181
|
-
const letters = arg.slice(1, -1).split("");
|
|
182
|
-
let broken = false;
|
|
183
|
-
for (let j = 0; j < letters.length; j++) {
|
|
184
|
-
const next = arg.slice(j + 2);
|
|
185
|
-
if (next === "-") {
|
|
186
|
-
setArg(letters[j], next, arg);
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
|
190
|
-
setArg(letters[j], next.split(/=(.+)/)[1], arg);
|
|
191
|
-
broken = true;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
if (/[A-Za-z]/.test(letters[j]) &&
|
|
195
|
-
/-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
|
196
|
-
setArg(letters[j], next, arg);
|
|
197
|
-
broken = true;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
|
201
|
-
setArg(letters[j], arg.slice(j + 2), arg);
|
|
202
|
-
broken = true;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const [key] = arg.slice(-1);
|
|
210
|
-
if (!broken && key !== "-") {
|
|
211
|
-
if (args[i + 1] &&
|
|
212
|
-
!/^(-|--)[^-]/.test(args[i + 1]) &&
|
|
213
|
-
!get(flags.bools, key) &&
|
|
214
|
-
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
215
|
-
setArg(key, args[i + 1], arg);
|
|
216
|
-
i++;
|
|
217
|
-
}
|
|
218
|
-
else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
|
|
219
|
-
setArg(key, args[i + 1] === "true", arg);
|
|
220
|
-
i++;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
229
|
-
argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg));
|
|
230
|
-
}
|
|
231
|
-
if (stopEarly) {
|
|
232
|
-
argv._.push(...args.slice(i + 1));
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
for (const key of Object.keys(defaults)) {
|
|
238
|
-
if (!hasKey(argv, key.split("."))) {
|
|
239
|
-
setKey(argv, key.split("."), defaults[key]);
|
|
240
|
-
if (aliases[key]) {
|
|
241
|
-
for (const x of aliases[key]) {
|
|
242
|
-
setKey(argv, x.split("."), defaults[key]);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (doubleDash) {
|
|
248
|
-
argv["--"] = [];
|
|
249
|
-
for (const key of notFlags) {
|
|
250
|
-
argv["--"].push(key);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
for (const key of notFlags) {
|
|
255
|
-
argv._.push(key);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return argv;
|
|
259
|
-
}
|
|
260
|
-
exports.parse = parse;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseDateLike = void 0;
|
|
4
|
-
function parseDateLike(date) {
|
|
5
|
-
if (typeof date === "string") {
|
|
6
|
-
date = new Date(date);
|
|
7
|
-
}
|
|
8
|
-
if (!(date instanceof Date) && typeof date !== "number") {
|
|
9
|
-
throw new TypeError(`Expected "year" type to be "Date" | "number" | "string" and got ${typeof date}.`);
|
|
10
|
-
}
|
|
11
|
-
return date instanceof Date ? date.getUTCFullYear() : date;
|
|
12
|
-
}
|
|
13
|
-
exports.parseDateLike = parseDateLike;
|
package/script/leap-year.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
require("./_dnt.polyfills.js");
|
|
28
|
-
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
29
|
-
const mod_js_1 = require("./deps/deno.land/std@0.128.0/flags/mod.js");
|
|
30
|
-
const mod_js_2 = require("./mod.js");
|
|
31
|
-
const { _: years, verbose } = (0, mod_js_1.parse)(dntShim.Deno.args, {
|
|
32
|
-
boolean: ["verbose"],
|
|
33
|
-
alias: { v: "verbose" },
|
|
34
|
-
});
|
|
35
|
-
for (const year of years) {
|
|
36
|
-
const { year: parsedYear, result } = (0, mod_js_2.isLeapYear)(year, true);
|
|
37
|
-
if (verbose) {
|
|
38
|
-
console.log(`${parsedYear} is ${result ? "" : "not "}a leap year.`);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
console.log(result);
|
|
42
|
-
}
|
package/script/mod.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLeapYear = void 0;
|
|
4
|
-
require("./_dnt.polyfills.js");
|
|
5
|
-
const mod_js_1 = require("./deps/deno.land/x/parse_datelike@0.0.1/mod.js");
|
|
6
|
-
function isLeapYear(year = new Date(), returnValue = false) {
|
|
7
|
-
year = (0, mod_js_1.parseDateLike)(year);
|
|
8
|
-
const result = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
9
|
-
return returnValue ? { result, year } : result;
|
|
10
|
-
}
|
|
11
|
-
exports.isLeapYear = isLeapYear;
|
package/script/package.json
DELETED
package/types/_dnt.shims.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export interface Args {
|
|
2
|
-
/** Contains all the arguments that didn't have an option associated with
|
|
3
|
-
* them. */
|
|
4
|
-
_: Array<string | number>;
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
export interface ArgParsingOptions {
|
|
8
|
-
/** When `true`, populate the result `_` with everything before the `--` and
|
|
9
|
-
* the result `['--']` with everything after the `--`. Here's an example:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* // $ deno run example.ts -- a arg1
|
|
13
|
-
* import { parse } from "./mod.ts";
|
|
14
|
-
* console.dir(parse(Deno.args, { "--": false }));
|
|
15
|
-
* // output: { _: [ "a", "arg1" ] }
|
|
16
|
-
* console.dir(parse(Deno.args, { "--": true }));
|
|
17
|
-
* // output: { _: [], --: [ "a", "arg1" ] }
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* Defaults to `false`.
|
|
21
|
-
*/
|
|
22
|
-
"--"?: boolean;
|
|
23
|
-
/** An object mapping string names to strings or arrays of string argument
|
|
24
|
-
* names to use as aliases */
|
|
25
|
-
alias?: Record<string, string | string[]>;
|
|
26
|
-
/** A boolean, string or array of strings to always treat as booleans. If
|
|
27
|
-
* `true` will treat all double hyphenated arguments without equal signs as
|
|
28
|
-
* `boolean` (e.g. affects `--foo`, not `-f` or `--foo=bar`) */
|
|
29
|
-
boolean?: boolean | string | string[];
|
|
30
|
-
/** An object mapping string argument names to default values. */
|
|
31
|
-
default?: Record<string, unknown>;
|
|
32
|
-
/** When `true`, populate the result `_` with everything after the first
|
|
33
|
-
* non-option. */
|
|
34
|
-
stopEarly?: boolean;
|
|
35
|
-
/** A string or array of strings argument names to always treat as strings. */
|
|
36
|
-
string?: string | string[];
|
|
37
|
-
/** A function which is invoked with a command line parameter not defined in
|
|
38
|
-
* the `options` configuration object. If the function returns `false`, the
|
|
39
|
-
* unknown option is not added to `parsedArgs`. */
|
|
40
|
-
unknown?: (arg: string, key?: string, value?: unknown) => unknown;
|
|
41
|
-
}
|
|
42
|
-
/** Take a set of command line arguments, with an optional set of options, and
|
|
43
|
-
* return an object representation of those argument.
|
|
44
|
-
*
|
|
45
|
-
* ```ts
|
|
46
|
-
* import { parse } from "./mod.ts";
|
|
47
|
-
* const parsedArgs = parse(Deno.args);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare function parse(args: string[], { "--": doubleDash, alias, boolean, default: defaults, stopEarly, string, unknown, }?: ArgParsingOptions): Args;
|
package/types/leap-year.d.ts
DELETED
/package/{LICENSE → license}
RENAMED
|
File without changes
|