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

@dongxiang678/dtejs

v1.0.3

Published

超轻量 TS 原生日期工具库,支持国际化、相对时间、日期比较

Readme

dtejs

超轻量(<2kB)JS 原生日期时间工具库,零依赖、支持国际化、API 极简易用。

npm version

✨ 特性

  • 🚀 超轻量:压缩后小于 2kB,零任何依赖
  • 👨‍💻 TypeScript 原生:完整类型定义,IDE 智能提示
  • 🌍 国际化支持:内置中文/英文,易扩展多语言
  • 智能相对时间:自动识别过去/未来(5分钟前、2天后)
  • 📦 优雅链式调用:简洁流畅的 API 设计
  • 🛡️ 完善边界容错:兼容各类异常日期格式

📦 安装

npm install dtelib
# 或
yarn add dtelib
# 或
pnpm add dtelib

🚀 快速上手

import { Dte, format, fromNow } from 'dtelib';

// 基础日期格式化
format('2026-03-20', 'YYYY-MM-DD'); // '2026-03-20'
format('2026-03-20', 'YYYY年MM月DD日'); // '2026年03月20日'

// 智能相对时间(自动判断过去/未来)
fromNow(Date.now() - 5 * 60 * 1000); // '5分钟前'
fromNow(Date.now() + 3 * 24 * 3600 * 1000, 'en-US'); // '3 days later'

// 链式日期计算
const tomorrow = new Dte('2026-03-20')
  .add(1, 'day')
  .format('YYYY-MM-DD'); // '2026-03-21'

// 日期大小对比
Dte.compare('2026-03-20', '2026-03-19'); // 1(大于)
Dte.compare('2026-03-20', '2026-03-20'); // 0(相等)

📖 API 文档

类:Dte

构造函数

new Dte(date?: Date | number | string, locale?: 'zh-CN' | 'en-US')

| 参数 | 类型 | 默认值 | 说明 | | ------ | ------------------------ | -------- | -------------------------- | | date | Date | number | string | 当前时间 | 日期对象/时间戳/日期字符串 | | locale | zh-CN | en-US | zh-CN | 语言环境 |

实例方法

  • format(template):格式化日期
    支持模板:YYYY-MM-DD / YYYY-MM-DD HH:mm:ss / YYYY年MM月DD日
  • fromNow():获取相对当前时间文案
  • add(amount, unit):日期增量(秒/分/时/天,返回新实例)
  • timestamp(type):获取时间戳(默认毫秒,可选秒)

静态方法

  • Dte.compare(date1, date2):对比两日期,返回 1/-1/0

快捷工具函数

  • format(date, template, locale?):无需实例,快速格式化
  • fromNow(date, locale?):无需实例,快速获取相对时间

🌍 国际化

内置 2 种语言,默认中文

// 实例切换英文
new Dte(Date.now() - 3600000, 'en-US').fromNow(); // 1 hour ago

// 函数切换英文
fromNow(Date.now() + 86400000, 'en-US'); // 1 day later

📊 竞品对比

| 特性 | dtelib | dayjs | moment | | ---------- | -------- | -------- | ------------ | | 体积 | <2kB | ~2kB | ~200kB | | TypeScript | 原生支持 | 需适配 | 需额外类型包 | | 依赖 | 零依赖 | 零依赖 | 冗余依赖 | | 维护状态 | 持续活跃 | 持续活跃 | 已停止维护 |

📄 许可证

MIT © dtelib

🔗 相关链接