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

@dpzj/select-user-core

v0.2.1

Published

Framework-agnostic person picker core for @dpzj/select-user

Readme

@dpzj/select-user-core

@dpzj/select-user 家族的框架无关核心逻辑:人员字段归一化、列表解包、树裁剪、选择态计算。

不依赖 Vue / Element / Ant Design。

安装

npm install @dpzj/select-user-core

UI 包(@dpzj/select-user / @dpzj/select-user-vue3-element / @dpzj/select-user-vue3-antd)内部使用本包,业务侧一般不需要直接安装。

常用导出

import {
  normalizePerson,
  normalizePersonList,
  getPersonKey,
  unwrapList,
  filterTreeByChildId,
  filterPersonsByKeyword,
  filterPersonsByRole,
  mapGroupNodes,
  mapGroupUsers,
  toggleSelectedUsers,
  mergeSelectAll,
  isPersonSelected,
  resolveOpenOptions
} from '@dpzj/select-user-core'

API

人员归一化

normalizePerson(user)

将异构人员字段统一为稳定形状,额外字段原样保留。

| 输出字段 | 来源 | |---|---| | id / userId | 互相兜底 | | username / userCode | 互相兜底 | | nickname / userName | 互相兜底 |

normalizePerson({ userId: 1, userCode: 'zhangsan', userName: '张三' })
// => { userId: 1, id: 1, userCode: 'zhangsan', username: 'zhangsan', userName: '张三', nickname: '张三' }

normalizePersonList(list)

批量归一化并按 getPersonKey 去重。

getPersonKey(person)

稳定主键,优先级:username → userCode → id → userId → nickname → userName。

列表与树

unwrapList(payload)

兼容多种接口返回形态,始终返回数组:

  • []
  • { data: [] }
  • { data: { list: [] } }
  • { list: [] }

其它情况返回 []。

filterTreeByChildId(nodes, targetId)

按子节点 id 裁剪组织树,保留从根到目标节点的路径;命中目标节点时保留其完整 children。

filterPersonsByKeyword(list, keyword)

按 nickname 模糊过滤。

filterPersonsByRole(list, userRole)

按 postIds 包含关系过滤;userRole 为空时不过滤。

群组

mapGroupNodes(groups)

将群组列表包装为树根节点:

// 输出
[{
  name: '个人群组',
  id: '0000000',
  children: [{ ...item, name: item.groupName || item.name, children: [] }]
}]

mapGroupUsers(group)

读取 group.groupUserList 或 group.users,并归一化人员字段。

选择态

toggleSelectedUsers(selected, person, options?)

切换选中态。options:

| 字段 | 默认 | 说明 | |---|---|---| | isRadio | false | 单选时直接替换为当前人 | | getKey | p => p.username \|\| p.id \|\| '' | 主键函数 |

mergeSelectAll(selected, currentList, checked, getKey?)

当前列表全选 / 取消全选,不影响其它已选。

isPersonSelected(selected, person, getKey?)

判断是否已选。

打开参数

resolveOpenOptions(options)

将 open(options) 参数转换为兼容旧 API 的形态:

resolveOpenOptions({ multiple: false, deptId: '1', selected: [] })
// => { type: 'once', deptId: '1', userRole: '', selected: [], sameDeptOnly: false }

| 输入 | 输出 | |---|---| | multiple(默认 true) | type: 多选 '' / 单选 'once' | | deptId | deptId | | userRole | userRole | | selected | selected | | sameDeptOnly | sameDeptOnly |

入口

| 字段 | 值 | |---|---| | main | dist/index.cjs.js | | module | dist/index.esm.js | | exports | CJS + ESM |

开发

在 monorepo 根目录:

npm install
npm run build:core

相关包

| 包 | 说明 | |---|---| | @dpzj/select-user | Vue2 + Element UI | | @dpzj/select-user-vue3-element | Vue3 + Element Plus | | @dpzj/select-user-vue3-antd | Vue3 + ant-design-vue |

License

MIT