Add nodejs-license-file (#34242)

This commit is contained in:
Troy McKinnon 2019-03-27 12:20:54 -05:00 committed by Ron Buckton
parent b2f87aa2bb
commit bd3a42fcae
4 changed files with 81 additions and 0 deletions

25
types/nodejs-license-file/index.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
// Type definitions for nodejs-license-file 4.0
// Project: https://github.com/bushev/nodejs-license-file
// Definitions by: Troy McKinnon <https://github.com/trodi>
// 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;
}

View File

@ -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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }