From bd3a42fcaedda99739cde364c92d074ab3070ff4 Mon Sep 17 00:00:00 2001 From: Troy McKinnon Date: Wed, 27 Mar 2019 12:20:54 -0500 Subject: [PATCH] Add nodejs-license-file (#34242) --- types/nodejs-license-file/index.d.ts | 25 +++++++++++++++ .../nodejs-license-file-tests.ts | 32 +++++++++++++++++++ types/nodejs-license-file/tsconfig.json | 23 +++++++++++++ types/nodejs-license-file/tslint.json | 1 + 4 files changed, 81 insertions(+) create mode 100644 types/nodejs-license-file/index.d.ts create mode 100644 types/nodejs-license-file/nodejs-license-file-tests.ts create mode 100644 types/nodejs-license-file/tsconfig.json create mode 100644 types/nodejs-license-file/tslint.json diff --git a/types/nodejs-license-file/index.d.ts b/types/nodejs-license-file/index.d.ts new file mode 100644 index 0000000000..9f890e08a8 --- /dev/null +++ b/types/nodejs-license-file/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for nodejs-license-file 4.0 +// Project: https://github.com/bushev/nodejs-license-file +// Definitions by: Troy McKinnon +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function parse(options: ParseOptions): License; +export function generate(options: GenerateOptions): string; +export interface License { + valid: boolean; + serial: string; + data: any; +} +export interface ParseOptions { + publicKeyPath?: string; + publicKey?: string; + licenseFilePath?: string; + licenseFile?: string; + template: string; +} +export interface GenerateOptions { + privateKeyPath?: string; + privateKey?: string; + template: string; + data: any; +} diff --git a/types/nodejs-license-file/nodejs-license-file-tests.ts b/types/nodejs-license-file/nodejs-license-file-tests.ts new file mode 100644 index 0000000000..c806d5e69b --- /dev/null +++ b/types/nodejs-license-file/nodejs-license-file-tests.ts @@ -0,0 +1,32 @@ +import * as LicenseFile from "nodejs-license-file"; + +const template: string = [ + "====BEGIN LICENSE====", + "{{&name}}", + "{{&id}}", + "{{&serial}}", + "=====END LICENSE=====", +].join("\n"); + +const generateOpts: LicenseFile.GenerateOptions = { + privateKeyPath: "private_key.pem", + template, + data: { + name: "John Doe", + id: "123456789", + }, +}; + +/** License data you can write to file. */ +const licenseString: string = LicenseFile.generate(generateOpts); + +const parseOpts: LicenseFile.ParseOptions = { + publicKeyPath: "public_key.pem", + licenseFilePath: "license", + template, +}; +/** Parsed license obj */ +const license: LicenseFile.License = LicenseFile.parse(parseOpts); + +// Access license data (e.g., "name"): +license.data.name; diff --git a/types/nodejs-license-file/tsconfig.json b/types/nodejs-license-file/tsconfig.json new file mode 100644 index 0000000000..ac1a20d729 --- /dev/null +++ b/types/nodejs-license-file/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nodejs-license-file-tests.ts" + ] +} diff --git a/types/nodejs-license-file/tslint.json b/types/nodejs-license-file/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/nodejs-license-file/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }