-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tomorrow and yesterday commands (#5)
* Ignore vscode workspace. * Reformat readme (satisfy vscode markdown linter). * Improve error handling in cli. * Improve tests (number of args, invalid date). * Replace tabs with spaces in readme. * Support yesterday and tomorrow dates. * Update README with yesterday and tomorrow keywords. * Satisfy linter. * Update CLI help message Co-authored-by: Knut Kirkhorn <[email protected]>
- Loading branch information
1 parent
403a77f
commit a6a1c3b
Showing
5 changed files
with
53 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
# week-number-cli | ||
|
||
> 📅 Get the ISO 8601 week number of a date CLI | ||
## Installation | ||
|
||
```sh | ||
npm install --global @knutkirkhorn/week-number-cli | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
$ week-number --help | ||
|
||
Usage | ||
$ week-number | ||
$ week-number <date> | ||
Examples | ||
$ week-number | ||
$ week-number "September 3, 2019 23:15:30" | ||
Usage | ||
$ week-number | ||
$ week-number "<date>" | ||
$ week-number yesterday | ||
$ week-number tomorrow | ||
Examples | ||
$ week-number | ||
$ week-number "September 3, 2019 23:15:30" | ||
$ week-number yesterday | ||
``` | ||
|
||
## Related | ||
|
||
- [week-number](https://github.com/knutkirkhorn/week-number) - API for this module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
#!/usr/bin/env node | ||
|
||
import meow from 'meow'; | ||
import weekNumber from '@knutkirkhorn/week-number'; | ||
import weekNumber, {tomorrowWeekNumber, yesterdayWeekNumber} from '@knutkirkhorn/week-number'; | ||
|
||
const cli = meow(` | ||
Usage | ||
$ week-number | ||
$ week-number <date> | ||
$ week-number "<date>" | ||
$ week-number yesterday | ||
$ week-number tomorrow | ||
Examples | ||
$ week-number | ||
$ week-number "September 3, 2019 23:15:30" | ||
$ week-number yesterday | ||
`, { | ||
importMeta: import.meta | ||
}); | ||
|
||
const inputDate = cli.input[0]; | ||
|
||
if (cli.input.length === 0) { | ||
console.log(weekNumber()); | ||
} else if (cli.input.length === 1) { | ||
console.log(weekNumber(inputDate)); | ||
try { | ||
if (cli.input.length > 1) { | ||
throw new Error('Command takes 0 or 1 argument.'); | ||
} | ||
if (inputDate === 'yesterday') { | ||
console.log(yesterdayWeekNumber()); | ||
} else if (inputDate === 'tomorrow') { | ||
console.log(tomorrowWeekNumber()); | ||
} else { | ||
console.log(weekNumber(inputDate)); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters