Merge pull request #28403 from lal12/master

Added definitions for wink-tokenizer and string-format
This commit is contained in:
Daniel Rosenwasser
2018-08-27 17:34:56 -07:00
committed by GitHub
8 changed files with 231 additions and 0 deletions

26
types/string-format/index.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Type definitions for string-format 2.0
// Project: https://github.com/davidchambers/string-format
// Definitions by: Luca Lindhorst <https://github.com/lal12>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function Format(template: string, ...args: Array<({ [k: string]: any } | string)>): string;
interface Transformers {
[k: string]: (s: any) => string;
}
declare namespace Format {
/**
* create a format function with given transformers
* @param transformers functions which convert a string, indexed by a name
*/
function create(transformers: Transformers): (typeof Format);
/**
* @param prototype prototype which should be extended by format (usually String.prototype)
* @param transformers functions which convert a string, indexed by a name
*/
function extend(prototype: any, transformers: Transformers): void;
}
export = Format;

View File

@@ -0,0 +1,11 @@
import Format = require("string-format");
Format.extend(String.prototype, {});
const fmt = Format.create({
upper: (s: string) => s.toUpperCase()
});
fmt("Hallo {name!upper}, you are {age} years old!", { name: "Somebody", age: 10 });
Format("Hallo {name}, you are {age} years old!", { name: "Somebody", age: 10 });

View File

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

View File

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

135
types/wink-tokenizer/index.d.ts vendored Normal file
View File

@@ -0,0 +1,135 @@
// Type definitions for wink-tokenizer 4.0
// Project: http://winkjs.org/
// Definitions by: Luca Lindhorst <https://github.com/lal12>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Tokenizer {
/**
* create a tokenizer instance
*/
constructor();
/**
* Tokenize a string
* @param sentence to be tokenized
* @returns tokens
*/
tokenize(sentence: string): Tokenizer.Token[];
/**
* Defines the configuration in terms of the types of token that will be extracted by tokenize() method.
* Note by default, all types of tokens will be detected and tagged automatically.
* @param config configuration object
* @returns number of true parameters
*/
defineConfig(config: Tokenizer.Config): number;
/**
* Returns the finger print of the tokens generated by the last call to tokenize().
* A finger print is a string created by sequentially joining the unique code of each token's type.
*
* currency: 'r', email: 'e', emoji: 'j', emoticon: 'c',
* hashtag: 'h', number: 'n', ordinal: 'o',
* punctuation: token becomes fingerprint,
* quoted_phrase: 'q', symbol: token becomes fingerprint,
* time: 't', mention: 'm', url: 'u', word: 'w',
* @return string of token types
*/
getTokensFP(): string;
}
declare namespace Tokenizer {
type Tag = "word" | "email" | "emoji" | "punctuation"
| "number" | "time" | "hashtag" | "mention" | "emoticon" | "ordinal"
| "quoted_phrase" | "url" | "symbol" | "currency" | "alien";
interface Token {
value: string;
tag: Tag;
}
/**
* It defines 0 or more properties from the list of 14 properties.
* A true value for a property ensures tokenization for that type of text;
* whereas false value will mean that the tokenization of that type of text will not be attempted.
*
* An empty config object is equivalent to splitting on spaces.
* Whatever tokens are created like this are tagged as alien
* and z is the finger print code of this token type.
*/
interface Config {
/**
* such as $ or £ symbols
* @default true
*/
currency?: boolean;
/**
* @default true
*/
email?: boolean;
/**
* @default true
*/
emoji?: boolean;
/**
* @default true
*/
emoticon?: boolean;
/**
* @default true
*/
hashtag?: boolean;
/**
* @default true
*/
number?: boolean;
/**
* ordinals like 1st , 2nd , 3rd , 4th or 12th or 91st
* @default true
*/
ordinal?: boolean;
/**
* @default true
*/
punctuation?: boolean;
/**
* @default true
*/
quoted_phrase?: boolean;
/**
* @default true
*/
symbol?: boolean;
/**
* @default true
*/
time?: boolean;
/**
* @default true
*/
mention?: boolean;
/**
* @default true
*/
url?: boolean;
/**
* @default true
*/
word?: boolean;
}
}
export = Tokenizer;

View File

@@ -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",
"wink-tokenizer-tests.ts"
]
}

View File

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

View File

@@ -0,0 +1,11 @@
import * as Tokenizer from "wink-tokenizer";
const tokenizer = new Tokenizer();
tokenizer.defineConfig({
currency: false
});
tokenizer.tokenize("asd asd asd ads");
tokenizer.getTokensFP();