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

one-day-js

v0.1.5

Published

A javascript common use date utilities and compatible with typescript.

Downloads

7

Readme

one-day

A javascript common use date utilities and compatible with typescript.

Install

npm install one-day --save
yarn add one-day

Usage

calDate

calcDate(date: Date, calcType: 'add' | 'subtract', unitType: OpUnitType, value: number): Dayjs

Add or Subtract date by unit type.

Example

console.log(calcDate(new Date(date), 'add', 'day', 10).format('DD-MMM-YYYY'));
//expected output: "15-Apr-2020"

dayToTime

dayToTime(day: number, type?: 'ms' | 's' | 'm' | 'h'): number

Convert from day(s) to millisecond, second, minute and hour.

Example

console.log(dayToTime(1, 'h'));
//expected output: 24

fromNow

fromNow(date?: ConfigType): string

Returns the string of relative time from now

Example

console.log(fromNow(new Date()));
// expected output: "a second ago"

getFirstDayOfMonth

getFirstDayOfMonth(date: Date, type: 'Previous' | 'Current' | 'Next'): Dayjs

Get the first day of the month.

Example

const date = '2020-04-05';
const format = 'DD-MMM-YYYY';

console.log(getFirstDayOfMonth(new Date(date), 'Previous').format(format));
// expected output: '01-Mar-2020'

console.log(getFirstDayOfMonth(new Date(date), 'Current').format(format));
// expected output: '01-Apr-2020'

// Next month
console.log(getFirstDayOfMonth(new Date(date), 'Next').format(format));
// expected output: '01-May-2020'

getLastDayOfMonth

getLastDayOfMonth(date: Date, type: 'Previous' | 'Current' | 'Next'): Dayjs

Get the last day of the month.

Example

const date = '2020-04-05';
const format = 'DD-MMM-YYYY';

console.log(getLastDayOfMonth(new Date(date), 'Previous').format(format));
// expected output: '31-Mar-2020'

console.log(getLastDayOfMonth(new Date(date), 'Current').format(format));
// expected output: '30-Apr-2020'

console.log(getLastDayOfMonth(new Date(date), 'Next').format(format));
// expected output: '31-May-2020'

previousMonth

previousMonth(format?: string);

Get the first and last day of previous month.

Example

// '2020-04-05';
console.log(previousMonth());
// expected output: { from: '01-Mar-2020', to: '31-Mar-2020' }

previousWeek

previousWeek(format?: string);

Get the first and last day of previous week.

Example

// '2020-05-19';
console.log(previousWeek());
// expected output: { from: '10-May-2020', to: '16-May-2020' }

quarter

previousWeek(format?: string);

Gets the quarter of the year.

Example

// '2020-05-19';
// Get Current Quarter
quarter.current();
// expected output: { from: '01-Apr-2020', to: '30-Jun-2020' }

// Get Previous Quarter
quarter.previous();
// expected output: { from: '01-Jan-2020', to: '31-Mar-2020' }

// Get Specific Quarter
quarter.quarter(1);
// expected output: { from: '01-Jan-2020', to: '31-Mar-2020' }

smartTZ

smartTZ(utc: string, options?: smartTZOptions): string | Dayjs

Convert UTC date to specific time zone.

Example

const format = 'DD-MM-YYYY HH:mm:ss';
const UTCString = '2019-07-25T16:00:00.48Z';

smartTZ(UTCString, { timezone: 'Asia/Jakarta', format: format });
// expected output: 25-07-2019 23:00:00

thisMonth

thisMonth((format?: string));

Get the first and last day of current month.

Example

// 2020-05-19
thisMonth();
// expected output: { from: '01-May-2020', to: '31-May-2020' }

thisWeek

thisWeek((format?: string));

Get the first and last day of current week.

Example

// 2020-05-19
thisWeek();
// expected output: { from: '17-May-2020', to: '23-May-2020' }

thisYear

thisYear((format?: string));

Get the first and last day of current year.

Example

// 2020-05-19
thisYear();
// expected output: { from: '01-Jan-2020', to: '31-Dec-2020' }

today

today((format?: string));

Get today date.

Example

// 2020-05-19
today();
// expected output: { from: '19-May-2020', to: '19-May-2020' }

yesterday

today((format?: string));

Get yesterday date.

Example

// 2020-05-19
yesterday();
// expected output: { from: '18-May-2020', to: '18-May-2020' }