diff --git a/types/string-format/index.d.ts b/types/string-format/index.d.ts new file mode 100644 index 0000000000..43e8b7d127 --- /dev/null +++ b/types/string-format/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for string-format 2.0 +// Project: https://github.com/davidchambers/string-format +// Definitions by: Luca Lindhorst +// 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; diff --git a/types/string-format/string-format-tests.ts b/types/string-format/string-format-tests.ts new file mode 100644 index 0000000000..73d638fe98 --- /dev/null +++ b/types/string-format/string-format-tests.ts @@ -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 }); diff --git a/types/string-format/tsconfig.json b/types/string-format/tsconfig.json new file mode 100644 index 0000000000..ec3951f6f9 --- /dev/null +++ b/types/string-format/tsconfig.json @@ -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" + ] +} diff --git a/types/string-format/tslint.json b/types/string-format/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/string-format/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wink-tokenizer/index.d.ts b/types/wink-tokenizer/index.d.ts new file mode 100644 index 0000000000..11b9236cdc --- /dev/null +++ b/types/wink-tokenizer/index.d.ts @@ -0,0 +1,135 @@ +// Type definitions for wink-tokenizer 4.0 +// Project: http://winkjs.org/ +// Definitions by: Luca Lindhorst +// 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; diff --git a/types/wink-tokenizer/tsconfig.json b/types/wink-tokenizer/tsconfig.json new file mode 100644 index 0000000000..5ec43876c0 --- /dev/null +++ b/types/wink-tokenizer/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", + "wink-tokenizer-tests.ts" + ] +} diff --git a/types/wink-tokenizer/tslint.json b/types/wink-tokenizer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wink-tokenizer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wink-tokenizer/wink-tokenizer-tests.ts b/types/wink-tokenizer/wink-tokenizer-tests.ts new file mode 100644 index 0000000000..755127370e --- /dev/null +++ b/types/wink-tokenizer/wink-tokenizer-tests.ts @@ -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();