diff --git a/types/netrc/.npmignore b/types/netrc/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/netrc/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/netrc/index.d.ts b/types/netrc/index.d.ts new file mode 100644 index 00000000000000..8bb59f70e0827a --- /dev/null +++ b/types/netrc/index.d.ts @@ -0,0 +1,14 @@ +/// + +import fs from "fs"; + +export = netrc; + +declare function netrc(file?: fs.PathLike): netrc.Machines; + +declare namespace netrc { + type Machines = Record>; + function parse(content: string): Machines; + function format(machines: Machines): string; + function save(machines: Machines): void; +} diff --git a/types/netrc/netrc-tests.ts b/types/netrc/netrc-tests.ts new file mode 100644 index 00000000000000..51514ed8849052 --- /dev/null +++ b/types/netrc/netrc-tests.ts @@ -0,0 +1,28 @@ +import netrc from "netrc"; + +const machines = netrc(".mynetrc"); + +const { login, password } = machines["example.com"]; +// $ExpectType string +login; +// $ExpectType string +password; + +// $ExpectType string +netrc.format(machines); + +machines["github.com"] = { + login: "AzureDiamond", + password: "hunter2", +}; +// $ExpectType void +netrc.save(machines); + +// netrc-valid-w-comment from camshaft/netrc +const content = `# I am a comment +machine github.com + password 123 + login CamShaft +# I am another comment`; +// $ExpectType Machines +netrc.parse(content); diff --git a/types/netrc/package.json b/types/netrc/package.json new file mode 100644 index 00000000000000..dc1ba7a42e7d42 --- /dev/null +++ b/types/netrc/package.json @@ -0,0 +1,20 @@ +{ + "private": true, + "name": "@types/netrc", + "version": "0.1.9999", + "projects": [ + "https://github.com/CamShaft/netrc#readme" + ], + "dependencies": { + "@types/node": "*" + }, + "devDependencies": { + "@types/netrc": "workspace:." + }, + "owners": [ + { + "name": "Nate Kean", + "githubUsername": "nate-kean" + } + ] +} diff --git a/types/netrc/tsconfig.json b/types/netrc/tsconfig.json new file mode 100644 index 00000000000000..d472e7f9d8ea9a --- /dev/null +++ b/types/netrc/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "netrc-tests.ts" + ] +}