Merge pull request #30783 from pluma/ldap-filters

Added ldap-filters@2.2
This commit is contained in:
Andrew Casey
2018-12-07 11:19:45 -08:00
committed by GitHub
4 changed files with 105 additions and 0 deletions

60
types/ldap-filters/index.d.ts vendored Normal file
View File

@@ -0,0 +1,60 @@
// Type definitions for ldap-filters 2.2
// Project: https://github.com/tapmodo/node-ldap-filters
// Definitions by: Alan Plum <https://github.com/pluma>
// 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;

View File

@@ -0,0 +1,28 @@
/// <reference types="node" />
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));

View File

@@ -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"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }