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

date-cipher

v0.1.0

Published

二次封装的时间计算快捷函数使用库

Readme

date-cipher

NPM version Build Status GitHub forks GitHub stars NPM download GitHub license

二次封装的时间计算快捷函数使用库

methods

简单的格式化日期格式

/**
 * @method formatDate 简单的格式化日期格式
 *
 * @param {Date} date 需要被格式化的日期
 * @param {String} formatStr 格式化字符串
 *
 * @return {String} 返回格式化好的日期
 */

使用方式 =>

import { formatDate } from 'date-cipher'

console.log(formatDate())

计算周的起止时间

/**
 * @method s2eWeek 计算周的起止时间
 *
 * @param {Date} date 任意一天
 * @param {String} formatStr 格式化字符串
 * @param {Boolean} isCurrent 结束时间为当前时间
 *
 * @return {Object} 返回起止日期
 */

使用方式 =>

import { s2eWeek } from 'date-cipher'

console.log(s2eWeek())

计算月的起止时间

/**
 * @method s2eMonth 计算月的起止时间
 *
 * @param {Date} date 任意一天
 * @param {String} formatStr 格式化字符串
 * @param {Boolean} isCurrent 结束时间为当前时间
 *
 * @return {Object} 返回起止日期
 */

使用方式 =>

import { s2eMonth } from 'date-cipher'

console.log(s2eMonth())

计算年的起止时间

/**
 * @method s2eYear 计算年的起止时间
 *
 * @param {Date} date 任意一天
 * @param {String} formatStr 格式化字符串
 * @param {Boolean} isCurrent 结束时间为当前时间
 *
 * @return {Object} 返回起止日期
 */

使用方式 =>

import { s2eYear } from 'date-cipher'

console.log(s2eYear())

计算N天前或者N天后的日期

/**
 * @method dayByDays 计算N天前或者N天后的日期
 *
 * @param {Date} date 一年中任意一天
 * @param {String} formatStr 格式化字符串
 * @param {Number} days 计算天数
 * @param {String} type 计算的是之前的日期 before 之后的日期 after
 *
 * @return {Object} 默认返回昨天日期
 */

使用方式 =>

import { dayByDays } from 'date-cipher'

console.log(dayByDays())

计算N天前或者N天后的日期(起止日期)

/**
 * @method s2eDayByDays 计算N天前或者N天后的日期(起止日期)
 *
 * @param {String} formatStr 格式化字符串
 * @param {Number} days 计算天数
 * @param {String} type 计算的是之前的日期 before 之后的日期 after
 * @param {Boolean} isCurrent 是否包含今天
 *
 * @return {Object} 默认返回最近一周的起止日期
 */

使用方式 =>

import { s2eDayByDays } from 'date-cipher'

console.log(s2eDayByDays())

计算两个时间段的相差天数, 精确到 N 年 N 天 精确到小数后两位

/**
 * @method diffDays 计算两个时间段的相差天数,精确到 N 年 N 天 精确到小数后两位
 *
 * @param {Date} startDate 开始时间
 * @param {Date} endDate 结束时间
 * @param {Boolean} format 是否进行格式化,为 true 格式化成 N 年 N 天,为 false 直接返回未格式化的
 *
 * @return {String} 相差的天数
 */

使用方式 =>

import { diffDays } from 'date-cipher'

console.log(diffDays())