Skip to content

简介(Introduction)

nex-lib 是一个轻量的 JavaScript/TypeScript 前端工具库,专注常用业务场景:

  • 时间:格式化输出与时间戳获取
  • URL:主域名解析、查询参数解析/追加、协议/路径/端口获取
  • 校验:邮箱、URL、手机号、日期、邮编、身份证等常见输入验证
  • 对象与字符串:深合并、深比较、类型判断、树过滤、驼峰化、反转、省略、随机串、词频统计
  • 彩色日志:ANSI 彩色输出,提升调试可读性

特性:TypeScript 友好、支持 Tree‑shaking、零运行时依赖、ESM/CommonJS 双格式、稳定 API(遵循接口不随意变更)。

亮点(Highlights)

  • 轻量与按需:零运行时依赖 + Tree‑shaking
  • 完整类型:TypeScript 友好,IDE 智能提示
  • 全场景覆盖:时间 / URL / 校验 / 对象 / 字符串 / 彩色日志

控制台(Console Ready)

  • 文档站已注入常用对象:window.browserUtilswindow.Httpwindow.NumberUtilswindow.StorageUtils
  • DevTools 直接尝试:browserUtils.getLocaleInfo('zh-CN')browserUtils.getCommonLocaleTable()browserUtils.getPublicIP()

安装(Install)

bash
npm install nex-lib
bash
pnpm add nex-lib
bash
yarn add nex-lib

快速开始(Quick Start)

ts
import { format, getTimestamp, createWURL, ObjectUtils, StringUtils, ValidationUtils, EchoUtils } from 'nex-lib';

format();                 // 'YYYY-MM-DD HH:mm:ss'
getTimestamp();           // 毫秒时间戳

const u = createWURL('https://sub.example.com/path?foo=bar');
u.getMainDomain();        // 'example.com'
u.parseQueryParams();     // { foo: 'bar' }
u.addParamsToURL({ q: 'x' });

ValidationUtils.isValidEmail('a@b.com');
ObjectUtils.deepMerge({ a: 1 }, { b: 2 });
StringUtils.toCamelCase('hello_world');
EchoUtils.green('OK', { id: 1 });
ts
import { format, getTimestamp } from 'nex-lib'
format(0)
getTimestamp(0)
text
1970-01-01 00:00:00
0

CommonJS:

js
const { format, getTimestamp, createWURL, ObjectUtils, StringUtils, ValidationUtils, EchoUtils } = require('nex-lib');

兼容说明(Compatibility)

  • 统一使用命名导出:formatgetTimestamp
  • 双格式产物:dist/bundle.cjs.jsdist/bundle.esm.js,支持 Node.js 与各类打包器。

文档(Docs)

要求(Requirements)

  • Node.js 18+ / 20+
  • 任意现代打包器(Vite/Rollup/Webpack)均可使用

快速导航(Quick Navigation)

Released under the ISC License.