Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#46345 feat(create-banner): new module defi…
Browse files Browse the repository at this point in the history
…nition by @peterblazejewicz

- definition file
- tests

https://github.com/fengyuanchen/create-banner

Thanks!n
  • Loading branch information
peterblazejewicz committed Jul 28, 2020
1 parent f11aec7 commit 3e31d28
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
28 changes: 28 additions & 0 deletions types/create-banner/create-banner-tests.ts
@@ -0,0 +1,28 @@
import createBanner = require('create-banner');

createBanner();
createBanner({ case: 'camel-case' });
createBanner({ case: 'camelCase' });
createBanner({ case: 'Title Case', template: 'inline' });
createBanner({
template: `/*!
* @name v@version
* @license (c) @author.name
*/
`,
});
createBanner({
template: 'Hello world!',
});
createBanner({
data: {
name: 'Library.js',
},
});
createBanner({
case: 'param-case',
data: {
name: 'Library.js',
date: new Date().toISOString(),
},
});
73 changes: 73 additions & 0 deletions types/create-banner/index.d.ts
@@ -0,0 +1,73 @@
// Type definitions for create-banner 1.0
// Project: https://github.com/fengyuanchen/create-banner
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.2

/**
* Create a banner from a package.json file
*/
declare function createBanner(options?: createBanner.Options): string;

declare namespace createBanner {
interface Options {
/**
* The case of the package name in the banner. Not to change the package name case by default.
* @default ''
*/
case?: LiteralUnion<
| 'camel-case'
| 'capital-case'
| 'constant-case'
| 'dot-case'
| 'header-case'
| 'no-case'
| 'param-case'
| 'pascal-case'
| 'path-case'
| 'sentence-case'
| 'snake-case',
string
>;
/**
* The extra data for creating banner, will be merged into package data.
*/
data?: BannerData;
/**
* The package data for creating banner.
* If it is null, will read from the closest package.json file by default using the `read-pkg-up` package
* @default null;
*/
pkg?: {
[key: string]: unknown;
} | null;
/**
* The template for creating banner.
* Property using a dot path is supported by the `dot-prop` package.
* Other values will be used directly as a custom template.
* @default 'normal'
*/
template?: LiteralUnion<'normal' | 'simple' | 'inline', string>;
}

interface BannerData {
/**
* @default new Date().toISOString()
*/
date?: string;
/**
* @default new Date().getFullYear()
*/
year?: string;
[key: string]: unknown;
}

// @credit @sindresorhus/type-fest
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
// @credit @sindresorhus/type-fest
type LiteralUnion<LiteralType extends BaseType, BaseType extends Primitive> =
| LiteralType
| (BaseType & { _?: never });
}

export = createBanner;
16 changes: 16 additions & 0 deletions types/create-banner/tsconfig.json
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "create-banner-tests.ts"]
}
1 change: 1 addition & 0 deletions types/create-banner/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 3e31d28

Please sign in to comment.