From c0df17945ec4488f75c6eb4cc121926601e901fc Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Sat, 24 Nov 2018 02:11:50 +0100 Subject: [PATCH] Added ldap-filters@2.2 --- types/ldap-filters/index.d.ts | 60 ++++++++++++++++++++++++ types/ldap-filters/ldap-filters-tests.ts | 28 +++++++++++ types/ldap-filters/tsconfig.json | 16 +++++++ types/ldap-filters/tslint.json | 1 + 4 files changed, 105 insertions(+) create mode 100644 types/ldap-filters/index.d.ts create mode 100644 types/ldap-filters/ldap-filters-tests.ts create mode 100644 types/ldap-filters/tsconfig.json create mode 100644 types/ldap-filters/tslint.json diff --git a/types/ldap-filters/index.d.ts b/types/ldap-filters/index.d.ts new file mode 100644 index 0000000000..46e1c24fa8 --- /dev/null +++ b/types/ldap-filters/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for ldap-filters 2.2 +// Project: https://github.com/tapmodo/node-ldap-filters +// Definitions by: Alan Plum +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +interface Filter { + toString(indent?: boolean | number): string; + simplify(): Filter; + match(data: object): boolean; +} + +declare namespace Filter { + let escape_chars: string[]; + let indent: number; + let indent_char: string; + let collapse_not: boolean; + + function escape(value: string): string; + function unescape(value: string): string; + function parse(input: string): Filter; + function matchString(data: string | string[], filter: Filter): boolean; + function matchSubstring(data: string | string[], filter: Filter): boolean; + function matchApprox(data: string | string[], filter: Filter): boolean; + function matchGTE(data: string | string[], filter: Filter): boolean; + function matchLTE(data: string | string[], filter: Filter): boolean; + function attribute(name: string): Attribute; + function AND(filters: Filter[]): Group; + function OR(filters: Filter[]): Group; + function NOT(filter: Filter): GroupNot; + + interface Group { + type: string; + comp: string; + filters: Filter[]; + toString(indent?: boolean | number): string; + match(data: object): boolean; + } + + interface GroupNot extends Group { + simplify(): Filter; + } + + interface Attribute { + name: string; + escapeChars: string[]; + escape(value: string): string; + present(): Filter; + raw(value: string): Filter; + equalTo(value: string): Filter; + endsWith(value: string): Filter; + startsWith(value: string): Filter; + contains(value: string): Filter; + approx(value: string): Filter; + lte(value: string): Filter; + gte(value: string): Filter; + } +} + +export = Filter; diff --git a/types/ldap-filters/ldap-filters-tests.ts b/types/ldap-filters/ldap-filters-tests.ts new file mode 100644 index 0000000000..5111af785e --- /dev/null +++ b/types/ldap-filters/ldap-filters-tests.ts @@ -0,0 +1,28 @@ +/// + +import Filter = require("ldap-filters"); + +Filter.collapse_not = false; + +const output = Filter.AND([ + Filter.attribute("givenName").equalTo("jenny"), + Filter.attribute("sn").equalTo("jensen") +]); + +console.log(output.toString()); + +Filter.parse("(&(givenName=jenny)(sn=jensen))"); + +Filter.parse("(&(uid=jenny))").simplify(); + +const filter = Filter.parse( + "(&(givenName=jenny)(sn=jensen)(|(c=us)(st=ontario)))" +); + +filter.toString(); +filter.toString(true); +filter.toString(2); + +const parsed = Filter.parse("(&(givenName~=jeni)(sn=jensen))"); +const data = { givenName: "Jenny", sn: "Jensen" }; +console.log(parsed.match(data)); diff --git a/types/ldap-filters/tsconfig.json b/types/ldap-filters/tsconfig.json new file mode 100644 index 0000000000..9d4f5aa560 --- /dev/null +++ b/types/ldap-filters/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "ldap-filters-tests.ts"] +} diff --git a/types/ldap-filters/tslint.json b/types/ldap-filters/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ldap-filters/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }