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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nex-lib

v1.2.1

Published

前端业务中常用的业务工具类函数

Downloads

17

Readme

nex-lib

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

安装

你可以通过 npm 安装 nex-lib 包:

npm install nex-lib

使用

安装完成后,你可以在项目中导入并使用 nex-lib 的功能。

导入

// 导入 Time 类
import { Time } from 'nex-lib';

// 导入 CustomURL 类
import { CustomURL } from 'nex-lib';

使用 Time 类

Time 类提供了时间格式化和时间戳转换的功能。

import { Time } from 'nex-lib';

const time = new Time();

// 格式化当前时间
console.log(time.format());

// 格式化指定的秒数
console.log(time.format(1633072800));

// 获取当前时间戳
console.log(time.getTimestamp());

// 获取指定秒数的时间戳
console.log(time.getTimestamp(1633072800));

使用 CustomURL 类(v1.2.1)

CustomURL 类提供了 URL 处理的功能,如获取主域名和解析查询参数。

import { CustomURL } from 'nex-lib';

const url = new CustomURL('https://www.example.com/path?name=value');

// 获取主域名
console.log(url.getMainDomain()); // 输出: example.com

// 解析查询参数
console.log(url.parseQueryParams()); // 输出: { name: 'value' }

彩色日志输出(v1.2.1)

import { EchoUtils } from 'nex-lib';
// 使用 EchoUtils 对象
EchoUtils.red('This is a red message!');
EchoUtils.bgGreen('This is a message with a green background.');

WURL-URL 的各类解析 (v1.2.1)

import WURL from 'nex-lib';

const url = new WURL('https://example.com:8080/path?query=123');

console.log(url.getMainDomain());  // 输出: example.com
console.log(url.parseQueryParams());  // 输出: { query: '123' }
console.log(url.isHttps());  // 输出: true
console.log(url.getPathname());  // 输出: /path
console.log(url.getPort());  // 输出: 8080

ObjectUtils (v1.2.1)

import ObjectUtils from 'nex-lib';

// 使用 ObjectUtils
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 }, e: 4 };
const merged = ObjectUtils.deepMerge(obj1, obj2);
console.log(merged);

// 其他使用示例
console.log(ObjectUtils.deepEqual({ a: 1 }, { a: 1 })); // true
console.log(ObjectUtils.keys({ a: 1, b: 2 })); // ['a', 'b']
console.log(ObjectUtils.values({ a: 1, b: 2 })); // [1, 2]
console.log(ObjectUtils.judgeTypes([1, 2, 3])); // 'array'

ValidationUtils (v1.2.1)

import ValidationUtils from 'nex-lib';

const email = '[email protected]';
const url = 'https://example.com';
const phone = '12345678901';
const date = '2024-09-12';
const postalCode = '123456';
const idCard = '110101199003076515';

// 验证邮箱
console.log(ValidationUtils.isValidEmail(email));  // 输出: true

// 验证 URL
console.log(ValidationUtils.isValidURL(url));  // 输出: true

// 验证电话号码
console.log(ValidationUtils.isValidPhoneNumber(phone));  // 输出: true

// 验证日期字符串
console.log(ValidationUtils.isValidDate(date));  // 输出: true

// 验证邮政编码
console.log(ValidationUtils.isValidPostalCode(postalCode));  // 输出: true

// 验证身份证号码
console.log(ValidationUtils.isValidIDCard(idCard));  // 输出: true