From 79b80371d94e258c2cc1eeee41625ccc212369f6 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 7 Feb 2018 12:22:49 +0000 Subject: removed types from options.ts to remove ts-node ambiguity --- src/matcher/options.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index 1ffa24e..b356c7b 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -1,9 +1,6 @@ import { default as types } from './types'; -type matchType - = (boolean | ((T) => boolean)); - -export function match(template: Object, value?: Object): matchType { +export function match(template: Object, value?: Object) { if (value === undefined) { return match.bind(null, template); } @@ -16,7 +13,7 @@ export function match(template: Object, value?: Object): matchType { return true; } -export function exact(template: Object, value?: Object): matchType { +export function exact(template: Object, value?: Object) { if (value === undefined) { return exact.bind(null, template); } @@ -28,7 +25,7 @@ export function exact(template: Object, value?: Object): matchType { && k2.every((x) => k1.indexOf(x) < 0); } -export function optional(template: Function, value?: any): matchType { +export function optional(template: Function, value?: any) { if (value === undefined) { return optional.bind(null, template); } @@ -37,7 +34,7 @@ export function optional(template: Function, value?: any): matchType { || template(value); } -export function alternative(templates: any[], value?: any): matchType { +export function alternative(templates: any[], value?: any) { if (value === undefined) { return alternative.bind(null, templates); } @@ -58,8 +55,7 @@ export function alternative(templates: any[], value?: any): matchType { } } -export function array(template: Object, values?: Array): -matchType> { +export function array(template: Object, values?: Array) { if (values === undefined) { return array.bind(null, template); } -- cgit v1.2.1 From f60e3d9858f6037db3b27d5574ac95310127d302 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 7 Feb 2018 12:48:48 +0000 Subject: matching now supports nested functions --- src/matcher/options.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index b356c7b..e93c2fd 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -6,7 +6,13 @@ export function match(template: Object, value?: Object) { } for (let k of Object.keys(template)) { - if (!template[k](value[k])) { + let f; + if (types.object(template[k])) { + f = match(template[k]); + } else { + f = template[k]; + } + if (!f(value[k])) { return false; } } -- cgit v1.2.1 From 5e482ce4408f2e1926d1e9af3270a52ffcc83df6 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 7 Feb 2018 14:18:55 +0000 Subject: added literal matching --- src/matcher/options.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index e93c2fd..2e65105 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -9,9 +9,12 @@ export function match(template: Object, value?: Object) { let f; if (types.object(template[k])) { f = match(template[k]); - } else { + } else if (types.function(template[k])) { f = template[k]; + } else { + f = (v) => v === template[k]; } + if (!f(value[k])) { return false; } -- cgit v1.2.1 From 05f1604a853bb3e2a066ceab1305abbc11d1d99d Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 8 Feb 2018 18:33:40 +0000 Subject: Revert "Revert "Merge branch 'testing'"" This reverts commit 0a9ebb01c27ed0a648922d243e877194977ce4d1. --- src/matcher/options.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index 2e65105..7412675 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -1,5 +1,8 @@ import { default as types } from './types'; +type matchType + = (boolean | ((T) => boolean)); + export function match(template: Object, value?: Object) { if (value === undefined) { return match.bind(null, template); -- cgit v1.2.1 From 7913e19e2f83296dc96a67e6437f6006b1d894ac Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 9 Feb 2018 05:59:48 +0000 Subject: various work I forgot to commit --- src/matcher/options.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index 7412675..c1d1aeb 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -75,3 +75,12 @@ export function array(template: Object, values?: Array) { let m = match(template) as ((Object) => boolean); return values.every(m); } + +const options = { + match = match, + exact = exact, + optional = optional, + alternative = alternative, + array = array +}; +export default options; -- cgit v1.2.1 From 3b4320c569dbf962af8a35ca0f16519a1de128db Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 9 Feb 2018 16:17:35 +0000 Subject: minor fixes --- src/matcher/options.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/matcher/options.ts') diff --git a/src/matcher/options.ts b/src/matcher/options.ts index c1d1aeb..9b07163 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -77,10 +77,10 @@ export function array(template: Object, values?: Array) { } const options = { - match = match, - exact = exact, - optional = optional, - alternative = alternative, - array = array + match : match, + exact : exact, + optional : optional, + alternative : alternative, + array : array }; export default options; -- cgit v1.2.1