diff options
| author | Tom Harley | 2018-02-07 00:18:33 +0000 |
|---|---|---|
| committer | Tom Harley | 2018-02-07 00:18:33 +0000 |
| commit | 0a9ebb01c27ed0a648922d243e877194977ce4d1 (patch) | |
| tree | e92e80940f110eef905b9e3a69908dab738178e8 /src/matcher/options.ts | |
| parent | Merge branch 'testing' (diff) | |
| download | medicine-0a9ebb01c27ed0a648922d243e877194977ce4d1.tar.gz medicine-0a9ebb01c27ed0a648922d243e877194977ce4d1.zip | |
Revert “Merge branch ‘testing’”
This reverts commit 1520a13a7144e6a0569f589d3aa5fdddc8136b8c, reversing changes made to de143da2021f8b972966be36b6bce26245c87e37.
Diffstat (limited to 'src/matcher/options.ts')
| -rw-r--r-- | src/matcher/options.ts | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/matcher/options.ts b/src/matcher/options.ts deleted file mode 100644 index 1ffa24e..0000000 --- a/src/matcher/options.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { default as types } from './types'; - -type matchType<T = any> - = (boolean | ((T) => boolean)); - -export function match(template: Object, value?: Object): matchType<Object> { - if (value === undefined) { - return match.bind(null, template); - } - - for (let k of Object.keys(template)) { - if (!template[k](value[k])) { - return false; - } - } - return true; -} - -export function exact(template: Object, value?: Object): matchType<Object> { - if (value === undefined) { - return exact.bind(null, template); - } - - let k1 = Object.keys(template); - let k2 = Object.keys(value); - - return match(template, value) - && k2.every((x) => k1.indexOf(x) < 0); -} - -export function optional(template: Function, value?: any): matchType<any> { - if (value === undefined) { - return optional.bind(null, template); - } - - return types.undefined(value) - || template(value); -} - -export function alternative(templates: any[], value?: any): matchType<any> { - if (value === undefined) { - return alternative.bind(null, templates); - } - - if (templates.length === 0) { - return false; - } else { - let t = templates.map((x) => { - if (types.function(x)) { - return x; - } else if (types.object(x)) { - return match(x); - } else { - return (v) => x === v; - } - }); - return t.some((x) => x(value)); - } -} - -export function array(template: Object, values?: Array<Object>): -matchType<Array<Object>> { - if (values === undefined) { - return array.bind(null, template); - } - - let m = match(template) as ((Object) => boolean); - return values.every(m); -} |
