Skip to content

nex-lib 是一个前端工具库,包含了一些常用的工具函数和类,旨在提高你的开发效率。这个库提供了实用的功能,如时间格式化、URL 处理等。

License

Notifications You must be signed in to change notification settings

webkubor/nex-lib

Repository files navigation

nex-lib logo

nex-lib — JavaScript/TypeScript Utility Library

npm version npm downloads license TypeScript

Documentation

nex-lib screenshot

轻量、类型友好、支持 Tree‑shaking 的前端工具库。聚焦常用场景:时间格式化、URL 解析、输入校验、对象/字符串工具、控制台彩色日志。

SEO 关键词:JavaScript utils、TypeScript utils、date format、URL parse、validation、object utils、string utils、colorful console, deep merge, camelCase。

安装(Install)

# npm
npm install nex-lib

# pnpm
pnpm add nex-lib

# yarn
yarn add nex-lib

快速开始(Quick Start)

ESM 用法:

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

// 时间格式化 / 时间戳
format();                 // 'YYYY-MM-DD HH:mm:ss'
format(1633072800);       // 指定秒数
getTimestamp();           // 毫秒时间戳
getTimestamp(1633072800); // 指定秒数对应的毫秒

// URL 工具
const u = createWURL('https://sub.example.com/path?foo=bar');
u.getMainDomain();      // 'example.com'
u.parseQueryParams();   // { foo: 'bar' }
u.addParamsToURL({ q: 'x' }); // 'https://sub.example.com/path?foo=bar&q=x'
u.isHttps();            // true
u.getPathname();        // '/path'
u.getPort();            // '80'(未显式端口时)

// 校验工具
ValidationUtils.isValidEmail('a@b.com');
ValidationUtils.isValidURL('https://example.com');
ValidationUtils.isValidPhoneNumber('1234567890');
ValidationUtils.isValidDate('2024-02-29');
ValidationUtils.isValidPostalCode('100000');
ValidationUtils.isValidIDCard('11010119900307123X');

// 对象工具
ObjectUtils.deepMerge({ a: 1 }, { b: 2 });
ObjectUtils.deepEqual({ a: 1 }, { a: 1 });
ObjectUtils.judgeTypes([]);      // 'array'
ObjectUtils.keys({ a: 1 });      // ['a']
ObjectUtils.values({ a: 1 });    // [1]

// 字符串工具
StringUtils.toCamelCase('hello_world');   // 'helloWorld'
StringUtils.reverseString('abc');         // 'cba'
StringUtils.ellipsisStr('abcdefghijklmn', 6, 4); // 'abcdef...jklmn'
StringUtils.createRandomStr(8);           // 随机串
StringUtils.countOccurrences('foofoo', 'foo'); // 2

// 彩色日志
EchoUtils.green('OK', { id: 1 });

CommonJS 用法:

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

特性(Features)

  • 时间工具:formatgetTimestamp(日期格式化、时间戳)
  • URL 工具:主域名提取、查询参数解析/追加、协议/路径/端口获取
  • 校验工具:邮箱、URL、手机号、日期、邮编、身份证等常见校验
  • 对象工具:深合并、深比较、类型判断、树结构过滤、键值获取
  • 字符串工具:驼峰化、反转、省略、随机串、词频统计、随机颜色
  • 彩色日志:标准 ANSI 彩色输出,调试更友好
  • TypeScript:完善类型定义,IDE 体验良好
  • Tree‑shaking:按需引入,减小包体积
  • 零运行时依赖:更轻、更稳

API 概览(API Overview)

  • format(seconds?: number): string
  • getTimestamp(seconds?: number): number
  • createWURL(url: string){ getMainDomain, parseQueryParams, addParamsToURL, isHttps, getPathname, getPort }
  • ObjectUtilsStringUtilsValidationUtilsEchoUtils

文档(Docs)

许可证(License)

  • ISC

About

nex-lib 是一个前端工具库,包含了一些常用的工具函数和类,旨在提高你的开发效率。这个库提供了实用的功能,如时间格式化、URL 处理等。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published