From 2b67b8a4e3f3c9721ce786799255979e2e66edb3 Mon Sep 17 00:00:00 2001 From: Yasunori Ohoka Date: Sat, 28 Oct 2017 09:18:25 +0900 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98moji=E2=80=99=20types=20(#21019)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add ‘moji’ types * moji: Fix tsconfig * moji: Fix tslint * moji: Fix tslint --- types/moji/index.d.ts | 32 ++++++++++++++++++++++++++++++++ types/moji/moji-tests.ts | 23 +++++++++++++++++++++++ types/moji/tsconfig.json | 24 ++++++++++++++++++++++++ types/moji/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/moji/index.d.ts create mode 100644 types/moji/moji-tests.ts create mode 100644 types/moji/tsconfig.json create mode 100644 types/moji/tslint.json diff --git a/types/moji/index.d.ts b/types/moji/index.d.ts new file mode 100644 index 0000000000..ae45f6ac26 --- /dev/null +++ b/types/moji/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for moji 0.5 +// Project: https://github.com/niwaringo/moji +// Definitions by: Yasunori Ohoka +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +declare namespace moji { + type Mojisyu = "ZE" | "HE" | "ZS" | "HS" | "HG" | "KK" | "ZK" | "HK"; + + interface MojisyuRange { + start: number; + end: number; + } + + interface MojisyuRegExp { + regexp: RegExp; + list: string[]; + } + + interface Moji { + convert(beforeType: Mojisyu, afterType: Mojisyu): Moji; + trim(): Moji; + filter(type: Mojisyu): Moji; + reject(type: Mojisyu): Moji; + toString(): string; + } + + function addMojisyu(type: string, mojisyu: MojisyuRange | MojisyuRegExp): void; +} + +declare function moji(moji: string): moji.Moji; +export = moji; diff --git a/types/moji/moji-tests.ts b/types/moji/moji-tests.ts new file mode 100644 index 0000000000..05be3e43c1 --- /dev/null +++ b/types/moji/moji-tests.ts @@ -0,0 +1,23 @@ +import moji = require('moji'); + +moji('ABCD01234').convert('ZE', 'HE').toString(); +moji('ABCD01234').convert('HE', 'ZE').toString(); +// tslint:disable-next-line:no-irregular-whitespace +moji(' ').convert('ZS', 'HS').toString(); +moji('あいうえお').convert('HG', 'KK').toString(); +moji('アイウエオ').convert('KK', 'HG').toString(); +moji('アイウエオ').convert('ZK', 'HK').toString(); +moji('アイウエオ').convert('HK', 'ZK').toString(); +moji('アイウエオ').convert('HK', 'ZK').convert('KK', 'HG').toString(); + +moji(' アイウエオ ').trim().toString(); + +moji('abcあいうアイウ123').filter('HG').toString(); + +moji('abcあいうアイウ123').reject('HG').toString(); + +moji.addMojisyu('ZE', { start: 0xff01, end: 0xff5e }); +moji.addMojisyu('HK', { + regexp: /([\uff66-\uff9c]\uff9e)|([\uff8a-\uff8e]\uff9f)|([\uff61-\uff9f])/g, + list: ["。", "「", "」"] +}); diff --git a/types/moji/tsconfig.json b/types/moji/tsconfig.json new file mode 100644 index 0000000000..a6b2e51f26 --- /dev/null +++ b/types/moji/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "moji-tests.ts" + ] +} diff --git a/types/moji/tslint.json b/types/moji/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/moji/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }