npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hongfangze-ldap

v0.0.2

Published

comm.ldap

Readme

LDAP域操作类

介绍

AD域的一些操作

开始使用

npm install hongfangze-ldap

类及成员定义

/**
     * Creates an instance of _LDAP.
     * @param {("ldap" | "ldaps")} [protocol="ldap"] 域控制器协议
     * @param {string} [host="127.0.0.1"] 域控制器IP地址
     * @param {string} adminAccount 具有域控管理权的管理员账户
     * @param {string} adminPassword 绑定DN管理员的密码
     * @param {string} baseOU 域根OU,如:OU=Users,OU=example,请查看distinguishedName里的一部分
     * @param {string} baseDN 域根DN,如:DC=example,DC=com
     * @param {number} [port=389] 域控制器端口,ldap一般为389,ldaps一般为636
     * @memberof _LDAP
     */
    constructor(protocol: "ldap" | "ldaps", host: string, adminAccount: string, adminPassword: string, baseOU: string, baseDN: string, port?: number);

    /**
     * 连接到LDAP服务器
     * @return {*}
     * @memberof _LDAP
     */
    connect(): Promise<void>;
    /**
     * 释放客户端
     * @return {*}
     * @memberof _LDAP
     */
    destroy(): Promise<void>;

    /**
     * 登录
     * @param {string} username
     * @param {string} password
     * @return {{
     *         result: boolean,
     *         message?: string,
     *     }} 是否成功及错误原因
     * @memberof _LDAP
     */
    login(username: string, password: string): Promise<{
        result: boolean;
        message?: string;
    }>;

    /**
     * 查询AD的组织架构(OU)
     * @param {("one" | "sub" | "base")} [scope="sub"] one=只查当前OU下一层,base=只查当前节点,sub=查询整个OU树
     * @param {boolean} [tree=true] 是否以树结构展示,默认true
     * @return {Idept[]} 组织架构对象
     * @memberof _LDAP
     */
    OU(scope?: "one" | "sub" | "base", tree?: boolean): Promise<Idept[]>;

    /**
     * 查询指定OU下的所有用户(排除AD内置系统账号)
     * @param {("one" | "sub" | "base")} [scope="sub"] one=只查当前OU下一层,base=只查当前节点,sub=查询整个OU树
     * @return {IUser[]} 用户列表
     * @memberof _LDAP
     */
    USER(scope?: "one" | "sub" | "base"): Promise<IUser[]>;

    /**
     * 获取部门及用户
     * @param {("one" | "sub" | "base")} [scope="sub"] 是否递归部门
     * @param {boolean} [tree=true] 是否以树结构返回部门,默认是
     * @return {Idept[]} 部门及用户信息
     * @memberof _LDAP
     */
    List(scope?: "one" | "sub" | "base", tree?: boolean): Promise<Idept[]>;

    /**
     * 搜索AD
     * @param {ISearchOptions} options 搜索条件
     * @return {*}
     * @memberof _LDAP
     */
    search(options: ISearchOptions): Promise<any>;

使用示例

import { LDAP } from "hongfangze-ldap";

// 初始化AD信息
const ldapInstance = new LDAP("ldap", "127.0.0.1", "admin", "password", "OU=Users,OU=example", "DC=example,DC=com");

// 连接到AD
await ldapInstance.connect();

// AD用户认证
res = await ldapInstance.login("username", "password");
console.log("认证结果:", res);

// 获取AD的OU信息
res = await ldapInstance.OU("sub");
console.log("OU树结构数据:", res);

// 获取AD的用户信息
res = await ldapInstance.USER("sub");
console.log("用户数据:", res);

// 获取AD的部门及用户
res = await ldapInstance.List("sub");
console.log("部门及用户数据:", res);

// 查询某个OU下的用户
res = await ldapInstance.search({
    filter: '(&(objectClass=user)(memberOf=CN=xxx,OU=xxx,OU=Users,OU=example,DC=example,DC=com))',
    scope: 'sub',
    attributes: ['*'],
});
console.log("查询结果:", res);

版本迭代记录

2026-03-13 v0.0.2

  • 基础框架搭建。