add pinyin 2.8.3 (#18344)

* add pinyin 2.8.3

* format code

* more meaningful parameters

* export Options

* support UMD

* add jsdoc

* add dom support for compilation

* add tslint.json

* fix lint error

* fix lint error
This commit is contained in:
wanganjun 2017-07-25 23:20:36 +08:00 committed by Andy
parent f1a8715e17
commit e160492009
4 changed files with 127 additions and 0 deletions

79
types/pinyin/index.d.ts vendored Normal file
View File

@ -0,0 +1,79 @@
// Type definitions for pinyin 2.8
// Project: https://github.com/hotoo/pinyin
// Definitions by: AnJun Wang <https://github.com/wanganjun>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = pinyin;
export as namespace pinyin;
/**
*
* @example
* pinyin("中心") // returns [ [ 'zhōng' ], [ 'xīn' ] ]
*/
declare function pinyin(words: string, options?: pinyin.Options): string[][];
declare namespace pinyin {
/**
* a b
* -1 a b
* 0 a b
* 1 a b
*/
function compare(a: string, b: string): -1 | 0 | 1;
/**
*
* pin yin
*/
const STYLE_NORMAL: number;
/**
*
* pīn yīn
*/
const STYLE_TONE: number;
/**
* 2 [0-4]
* pin1 yin1
*/
const STYLE_TONE2: number;
/**
* 3 [0-4]
* pi1n yi1n
*/
const STYLE_TO3NE: number;
/**
*
* zh g
* zh zch csh s
* 饿 y, w, yu ""
*/
const STYLE_INITIALS: number;
/**
*
* p y
*/
const STYLE_FIRST_LETTER: number;
interface Options {
/**
* {@link STYLE_TONE}
* @see {@link STYLE_NORMAL}
* @see {@link STYLE_TONE}
* @see {@link STYLE_TONE2}
* @see {@link STYLE_TO3NE}
* @see {@link STYLE_INITIALS}
* @see {@link STYLE_FIRST_LETTER}
*/
style?: number;
/**
*
* 使
*/
segment?: boolean;
/**
*
*
*
*/
heteronym?: boolean;
}
}

View File

@ -0,0 +1,24 @@
import pinyin = require("pinyin");
pinyin("中心");
pinyin("中心", {
heteronym: true
});
pinyin("中心", {
heteronym: true,
segment: true
});
const options: pinyin.Options = {
style: pinyin.STYLE_INITIALS,
heteronym: true
};
pinyin("中心", options);
pinyin.compare('测', '这');
pinyin.STYLE_NORMAL;
pinyin.STYLE_TONE;
pinyin.STYLE_TONE2;
pinyin.STYLE_TO3NE;
pinyin.STYLE_INITIALS;
pinyin.STYLE_FIRST_LETTER;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pinyin-tests.ts"
]
}

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

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