From efd7ae7dd16f7d27e4abf5ec1aa885c07f134e1c Mon Sep 17 00:00:00 2001 From: crissdev Date: Tue, 7 Jul 2015 15:56:05 +0300 Subject: [PATCH] improve definition for knockout.punches --- knockout.punches/knockout.punches-tests.ts | 24 ++++++++++++++++++- knockout.punches/knockout.punches.d.ts | 28 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/knockout.punches/knockout.punches-tests.ts b/knockout.punches/knockout.punches-tests.ts index bd5d53a5c5..bec2b1a4ef 100644 --- a/knockout.punches/knockout.punches-tests.ts +++ b/knockout.punches/knockout.punches-tests.ts @@ -2,7 +2,29 @@ function test_enable() { - ko.punches.enableAll(); +} +function test_filters() { + ko.filters.default([], 'Empty'); + ko.filters.default(null, 'Empty'); + ko.filters.default(0, 'Empty'); + ko.filters.default(' ', 'Empty'); + + ko.filters.fit('abcdef0123456789', 10); + ko.filters.fit('abcdef0123456789', 10, '_'); + ko.filters.fit('abcdef0123456789', 10, '_', 'left'); + ko.filters.fit('abcdef0123456789', 10, '_', 'middle'); + ko.filters.fit('abcdef0123456789', 10, '_', 'right'); + + ko.filters.json({}); + ko.filters.json({}, null, 4); + + ko.filters.number('123456789'); + ko.filters.number(12345.6789); + + ko.filters.lowercase('TEST'); + ko.filters.uppercase('test'); + + ko.filters.replace('1234abcd', '1234', ''); } \ No newline at end of file diff --git a/knockout.punches/knockout.punches.d.ts b/knockout.punches/knockout.punches.d.ts index d219d61f15..8bcb29ee89 100644 --- a/knockout.punches/knockout.punches.d.ts +++ b/knockout.punches/knockout.punches.d.ts @@ -9,8 +9,36 @@ interface KnockoutPunchesStatic { enableAll(): void; } +interface KnockoutPunchesFilters { + // Convert the value to uppercase. + uppercase(value: string): string; + + // Convert the value to lowercase. + lowercase(value: string): string; + + // Perform a search and replace on the value using String#replace. + replace(value: string, search: string, replace: string): string; + + // Trim the value if it’s longer than the given length. The trimmed portion is + // replaced with ... or the replacement value, if given. By default, the value + // is trimmed on the right but can be changed to left or middle through the + // where option. For example: name | fit:10::'middle' will + // convert Shakespeare to Shak...are. + fit(value: number | string, length?: number, replacement?: string, trimWhere?: string): string; + + // Convert the value to a JSON string using ko.toJSON. You can give a space value to format the JSON output. + json(rootObject: any, space?: any, replacer?: any): string; + + // Format the value using toLocaleString. + number(value: number | string): string; + + // If the value is blank, null, or an empty array, replace it with the given default value + default(value: any, defaultValue?: any): any; +} + interface KnockoutStatic { punches: KnockoutPunchesStatic; + filters: KnockoutPunchesFilters; } declare module "knockout.punches" {