From a0a52a6a3dab347444c8f79005ac255a0c67fda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Tue, 14 Apr 2020 00:27:17 +0200 Subject: [PATCH] feat(pre-suf): new type definition (#43866) - declaration file - tests https://github.com/kaelzhang/node-pre-suf Thanks! --- types/pre-suf/index.d.ts | 27 +++++++++++++++++++++++++++ types/pre-suf/pre-suf-tests.ts | 14 ++++++++++++++ types/pre-suf/tsconfig.json | 23 +++++++++++++++++++++++ types/pre-suf/tslint.json | 1 + 4 files changed, 65 insertions(+) create mode 100644 types/pre-suf/index.d.ts create mode 100644 types/pre-suf/pre-suf-tests.ts create mode 100644 types/pre-suf/tsconfig.json create mode 100644 types/pre-suf/tslint.json diff --git a/types/pre-suf/index.d.ts b/types/pre-suf/index.d.ts new file mode 100644 index 0000000000..a42e7a44c0 --- /dev/null +++ b/types/pre-suf/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for pre-suf 1.1 +// Project: https://github.com/kaelzhang/node-pre-suf#readme +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Manipulate strings with prefixes and suffixes. + */ + +/** + * Ensures that the new string will have prefix at the beginning of str. + * If str does not begin with prefix, prefix will be added to the beggining of str. + */ +export function ensureLeading(str: string, prefix: string): string; +/** + * Removes the leading prefix of str. + */ +export function removeLeading(str: string, prefix: string): string; +/** + * Ensures that the new string will have suffix at the end of str. + * If str does not end with suffix, suffix will be added at the end of str. + */ +export function ensureEnding(str: string, suffix: string): string; +/** + * Removes the ending suffix of str. + */ +export function removeEnding(str: string, suffix: string): string; diff --git a/types/pre-suf/pre-suf-tests.ts b/types/pre-suf/pre-suf-tests.ts new file mode 100644 index 0000000000..f2e86cdf01 --- /dev/null +++ b/types/pre-suf/pre-suf-tests.ts @@ -0,0 +1,14 @@ +import presuf = require('pre-suf'); + +presuf.ensureLeading('a', '/'); // $ExpectType string +presuf.removeLeading('a', '/'); // $ExpectType string +presuf.ensureEnding('a', '/'); // $ExpectType string +presuf.removeEnding('/a/ab/a', '/a'); // $ExpectType string +// $ExpectError +presuf.ensureLeading(); +// $ExpectError +presuf.removeLeading(); +// $ExpectError +presuf.ensureEnding(); +// $ExpectError +presuf.removeEnding(); diff --git a/types/pre-suf/tsconfig.json b/types/pre-suf/tsconfig.json new file mode 100644 index 0000000000..d5e1137ce2 --- /dev/null +++ b/types/pre-suf/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pre-suf-tests.ts" + ] +} diff --git a/types/pre-suf/tslint.json b/types/pre-suf/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pre-suf/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }