Add ‘moji’ types (#21019)

* Add ‘moji’ types

* moji: Fix tsconfig

* moji: Fix tslint

* moji: Fix tslint
This commit is contained in:
Yasunori Ohoka 2017-10-28 09:18:25 +09:00 committed by Sheetal Nandi
parent 1587233ac6
commit 2b67b8a4e3
4 changed files with 80 additions and 0 deletions

32
types/moji/index.d.ts vendored Normal file
View File

@ -0,0 +1,32 @@
// Type definitions for moji 0.5
// Project: https://github.com/niwaringo/moji
// Definitions by: Yasunori Ohoka <https://github.com/yasupeke>
// 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;

23
types/moji/moji-tests.ts Normal file
View File

@ -0,0 +1,23 @@
import moji = require('moji');
moji('').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: ["。", "「", "」"]
});

24
types/moji/tsconfig.json Normal file
View File

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

1
types/moji/tslint.json Normal file
View File

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