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

text2time

v1.1.8

Published

๐Ÿ•ฐ๏ธ Text2Time - Human-friendly date expressions for dates and cron expressions.

Downloads

11

Readme

๐Ÿ•ฐ๏ธ Text2Time: Natural Language Date Parser ๐Ÿš€

Text2Time is a rad JavaScript class that turns human-friendly date expressions into actual dates and cron expressions. It's like having a time-traveling assistant in your code! ๐Ÿ˜Ž

๐ŸŒŸ Features

  • Parse natural language date inputs
  • Generate cron expressions
  • Supports various time formats and intervals

๐Ÿš€ Getting Started

First, import the Text2Time class:

const t2t = new Text2Time();

๐Ÿ”ฎ Parsing Dates

Use the parse method to convert text to dates:

const result = t2t.parse('next tuesday');
console.log(result.date); // Next Tuesday's date

๐Ÿ”ฎ Parsing Dates

๐ŸŽญ Examples for next

const t2t = new Text2Time({ now: new Date('2023-05-15T12:00:00') });

t2t.next('tuesday').date // -> 2023-05-16 Tuesday 12:00
t2t.next('july second week friday').date // -> 2023-07-14 Friday 12:00
t2t.next('16 september').date // -> 2023-09-16 Saturday 12:00
t2t.next('july second week friday 15:15:10').date // -> 2023-07-14 Friday 15:15:10
t2t.next('30 11:11:11').date // -> 2023-05-30 Friday 11:11:11

// For date ranges
const result = t2t.next('august monday to thursday');
result.date // -> 2023-08-07 Monday 12:00
result.ends // -> 2023-08-10 Thursday 12:00

๐ŸŽญ Examples for add

const t2t = new Text2Time({ now: new Date('2023-05-15T12:00:00') });

t2t.next('add 1 day').date // -> 2023-05-16 Tuesday 12:00
t2t.next('add 7 days').date // -> 2023-05-22 Monday 12:00
t2t.next('add 1 week').date // -> 2023-05-22 Monday 12:00
t2t.next('add 1 month 15:00').date // -> 2023-06-15 Thursday 15:00

๐ŸŽญ Example with parse for next Occurrences

const t2t = new Text2Time({
    now: new Date('2023-05-15T12:00:00'),
    every: { next: 6 } // how many in next
});

const result = t2t.parse('every 3 months day 5 at 4:04');

result.next.forEach(date => { // Next 6 occurrences:
    // 2023-07-05 Wednesday 04:04
    // 2023-10-05 Thursday 04:04
    // 2024-01-05 Friday 04:04
    // 2024-04-05 Friday 04:04
    // 2024-07-05 Friday 04:04
    // 2024-10-05 Saturday 04:04
});

โฐ Generating Cron Expressions

Use the every method to create cron expressions:

const t2t = new Text2Time({ every:{ seconds:true } });

t2t.every('August At 00:05:10') // -> '10 5 0 * 8 *'
t2t.every('Friday and Monday At 04:05') // -> '0 5 4 * * 1,5'
t2t.every('5 minutes') // -> '0 */5 * * * *'
t2t.every('3 months day 5 at 4:04:01') // -> '1 4 4 5 */3 *'

๐ŸŽ‰ Why Text2Time is Awesome

  • ๐Ÿง  Understands human language
  • ๐Ÿ”ง Flexible and customizable
  • ๐Ÿš€ Easy to integrate
  • ๐ŸŽจ Makes working with dates and cron expressions fun!

Give Text2Time a spin and make your date parsing groovy! ๐Ÿ•บ๐Ÿ’ƒ

๐Ÿ“„ License

The MIT License (MIT)

Copyright (c) Martin Clasen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.