Skip to content

Commit c4936e9

Browse files
authored
🤖 Merge PR DefinitelyTyped#74858 [licensee] Add type definitions for licensee by @JamieMagee
1 parent 44a71ee commit c4936e9

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

‎types/licensee/.npmignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

‎types/licensee/index.d.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
declare function licensee(
2+
configuration: licensee.Configuration,
3+
path: string,
4+
callback: (error: Error | null, results?: licensee.Result[]) => void,
5+
): void;
6+
7+
declare namespace licensee {
8+
interface LicensesConfiguration {
9+
spdx?: string[] | undefined;
10+
blueOak?: string | undefined;
11+
osi?: boolean | undefined;
12+
}
13+
14+
interface IgnoreScope {
15+
scope: string;
16+
}
17+
18+
interface IgnorePrefix {
19+
prefix: string;
20+
}
21+
22+
interface IgnoreAuthor {
23+
author: string;
24+
}
25+
26+
type IgnoreRule = IgnoreScope | IgnorePrefix | IgnoreAuthor;
27+
28+
interface Configuration {
29+
licenses: LicensesConfiguration;
30+
packages?: Record<string, string> | undefined;
31+
corrections?: boolean | undefined;
32+
ignore?: IgnoreRule[] | undefined;
33+
productionOnly?: boolean | undefined;
34+
filterPackages?: ((dependencies: any[]) => any[]) | undefined;
35+
}
36+
37+
interface Result {
38+
name: string;
39+
version: string;
40+
license: string;
41+
author: any;
42+
contributors: any;
43+
repository: any;
44+
homepage: string;
45+
parent: any;
46+
path: string;
47+
approved: boolean;
48+
corrected?: "manual" | "automatic" | undefined;
49+
ignored?: boolean | undefined;
50+
package?: boolean | undefined;
51+
duplicates?: Result[] | undefined;
52+
}
53+
}
54+
55+
export = licensee;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import licensee = require("licensee");
2+
3+
const configuration: licensee.Configuration = {
4+
licenses: {
5+
spdx: ["MIT", "BSD-2-Clause", "BSD-3-Clause", "Apache-2.0"],
6+
},
7+
packages: {
8+
optimist: "<=0.6.1",
9+
},
10+
corrections: true,
11+
ignore: [
12+
{ scope: "kemitchell" },
13+
{ prefix: "commonform-" },
14+
{ author: "Kyle E. Mitchell" },
15+
],
16+
};
17+
18+
licensee(configuration, "/path/to/package", (error, results) => {
19+
if (error) {
20+
return;
21+
}
22+
if (results) {
23+
const result: licensee.Result = results[0];
24+
}
25+
});
26+
27+
const exampleResult: licensee.Result = {
28+
name: "example",
29+
version: "1.0.0",
30+
license: "MIT",
31+
author: null,
32+
contributors: null,
33+
repository: null,
34+
homepage: "",
35+
parent: null,
36+
path: "/path",
37+
approved: true,
38+
};
39+
40+
// $ExpectType string
41+
exampleResult.name;
42+
43+
// $ExpectType string
44+
exampleResult.version;
45+
46+
// $ExpectType string
47+
exampleResult.license;
48+
49+
// $ExpectType boolean
50+
exampleResult.approved;
51+
52+
const blueOakConfig: licensee.Configuration = {
53+
licenses: {
54+
blueOak: "bronze",
55+
},
56+
};
57+
58+
const osiConfig: licensee.Configuration = {
59+
licenses: {
60+
spdx: ["CC-BY-4.0"],
61+
blueOak: "gold",
62+
osi: true,
63+
},
64+
productionOnly: true,
65+
};
66+
67+
licensee(osiConfig, ".", (err, results) => {});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@types/licensee",
4+
"version": "12.0.9999",
5+
"projects": [
6+
"https://github.com/jslicense/licensee.js"
7+
],
8+
"devDependencies": {
9+
"@types/licensee": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "Jamie Magee",
14+
"githubUsername": "JamieMagee"
15+
}
16+
]
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"licensee-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)