Python's calendar.calendar in TypeScript
How to use
Install via yarn add locutus and import:
import { calendar } from 'locutus/python/calendar/calendar'.
Or with CommonJS: const { calendar } = require('locutus/python/calendar/calendar')
Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
| # | code | expected result |
|---|---|---|
| 1 | calendar(2024) | ' 2024\n\n January February March\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\n 1 2 3 4 5 6 7 1 2 3 4 1 2 3\n 8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10\n15 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17\n22 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24\n29 30 31 26 27 28 29 25 26 27 28 29 30 31\n\n April May June\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\n 1 2 3 4 5 6 7 1 2 3 4 5 1 2\n 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9\n15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16\n22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23\n29 30 27 28 29 30 31 24 25 26 27 28 29 30\n\n July August September\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\n 1 2 3 4 5 6 7 1 2 3 4 1\n 8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8\n15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15\n22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22\n29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29\n 30\n\n October November December\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\n 1 2 3 4 5 6 1 2 3 1\n 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8\n14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15\n21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22\n28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29\n 30 31\n' |
Dependencies
This function uses the following Locutus functions:
- _calendar (python/_helpers)
Here's what our current TypeScript equivalent to Python's calendar.calendar looks like.
import { |
Improve this function
Locutus is a community effort following The McDonald's Theory: we ship first iterations, hoping others will improve them. If you see something that could be better, we'd love your contribution.
View on GitHub · Edit on GitHub · View Raw
Help us add more
Got a rainy Sunday afternoon and a taste for a porting puzzle?
- Get inspiration from the Python 3 standard library string page.
- Click "New file" in the appropriate folder on GitHub. This will fork the project to your account, directly add the file to it, and send a Pull Request to us.
We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.
« More Python calendar functions
Star