devkits-timestamp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +127 -0
  2. package/index.js +128 -0
  3. package/package.json +48 -0
  4. package/test.js +60 -0
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # devkits-timestamp
2
+
3
+ > Convert Unix timestamps to human-readable dates and vice versa
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g devkits-timestamp
9
+ ```
10
+
11
+ Or use without installation:
12
+
13
+ ```bash
14
+ npx devkits-timestamp [args]
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ # Get current timestamp
21
+ dk-timestamp # 1704067200
22
+
23
+ # Convert timestamp to date
24
+ dk-timestamp 1704067200 # Full date info (JSON)
25
+ dk-timestamp 1704067200 -f iso # 2024-01-01T00:00:00.000Z
26
+ dk-timestamp 1704067200 -f utc # Mon, 01 Jan 2024 00:00:00 GMT
27
+ dk-timestamp 1704067200 -f date # 1/1/2024
28
+ dk-timestamp 1704067200 -f time # 12:00:00 AM
29
+
30
+ # Convert date to timestamp
31
+ dk-timestamp -d "2024-01-01" # 1704067200
32
+ dk-timestamp -d "Jan 1, 2024" # 1704067200
33
+ dk-timestamp -d "2024-01-01 12:00:00" # 1704110400
34
+
35
+ # Date to timestamp with format
36
+ dk-timestamp -d "2024-01-01" -f iso # 2024-01-01T00:00:00.000Z
37
+ ```
38
+
39
+ ## Why @devkits/timestamp?
40
+
41
+ - ✅ Fast - Instant conversion
42
+ - ✅ Zero dependencies - Pure Node.js
43
+ - ✅ Offline - Works without internet
44
+ - ✅ Free - Open source (MIT)
45
+ - ✅ CLI - Use in your terminal
46
+ - ✅ Multiple output formats
47
+
48
+ ## Output Formats
49
+
50
+ - `iso` - ISO 8601 format (2024-01-01T00:00:00.000Z)
51
+ - `utc` - UTC string (Mon, 01 Jan 2024 00:00:00 GMT)
52
+ - `local` - Local timezone string
53
+ - `date` - Date only (1/1/2024)
54
+ - `time` - Time only (12:00:00 AM)
55
+
56
+ ## Web Version
57
+
58
+ Prefer a GUI? Check out the web version: **https://devkits-tools.surge.sh/tools/timestamp**
59
+
60
+ - 84 developer tools in one PWA
61
+ - Works offline
62
+ - No signup required
63
+
64
+ ## Pro Features
65
+
66
+ Upgrade to Pro for advanced features:
67
+
68
+ - 📦 Batch Processing
69
+ - 🔗 API Access (1000 req/day free)
70
+ - ☁️ Cloud Sync
71
+ - 🎨 Custom Themes
72
+ - 📊 Advanced Analytics
73
+ - 💬 Priority Support
74
+
75
+ **Price:** $9 one-time payment
76
+ **Upgrade:** https://devkits-tools.surge.sh/pro
77
+ **Discount:** Use code `EARLYBIRD-2026` for 20% off
78
+
79
+ ## See Also
80
+
81
+ Part of the **[DevKits Tools](https://devkits-tools.surge.sh)** collection — 80+ free developer tools:
82
+
83
+ ### Popular Tools
84
+
85
+ | Tool | npm Package | Description |
86
+ |------|-------------|-------------|
87
+ | **[Base64](https://devkits-tools.surge.sh/tools/base64)** | `@devkits/base64` | Encode/decode Base64 |
88
+ | **[JSON Formatter](https://devkits-tools.surge.sh/tools/json-formatter)** | `@devkits/json-formatter` | Format and validate JSON |
89
+ | **[Color Converter](https://devkits-tools.surge.sh/tools/color-converter)** | `@devkits/color-converter` | HEX/RGB/HSL conversion |
90
+ | **[UUID Generator](https://devkits-tools.surge.sh/tools/uuid-generator)** | `@devkits/uuid-generator` | Generate unique UUIDs |
91
+ | **[Hash Generator](https://devkits-tools.surge.sh/tools/hash-generator)** | `@devkits/hash-generator` | MD5, SHA1, SHA256, SHA512 |
92
+ | **[Regex Tester](https://devkits-tools.surge.sh/tools/regex-tester)** | `@devkits/regex-tester` | Test regex patterns |
93
+
94
+ ### Other DevKits Tools
95
+
96
+ - **[HTML Tools](https://devkits-tools.surge.sh/tools/html-entities)** — HTML entity encode/decode
97
+ - **[CSS Tools](https://devkits-tools.surge.sh/tools/css-minifier)** — CSS minify/format
98
+ - **[Cron Parser](https://devkits-tools.surge.sh/tools/cron-parser)** — Parse cron expressions
99
+ - **[Case Convert](https://devkits-tools.surge.sh/tools/text-case)** — camelCase, snake_case, etc.
100
+ - **[Slugify](https://devkits-tools.surge.sh/tools/slug-generator)** — Create URL-friendly slugs
101
+ - **[Lorem Ipsum](https://devkits-tools.surge.sh/tools/lorem-ipsum)** — Generate placeholder text
102
+ - **[Password Generator](https://devkits-tools.surge.sh/tools/password-generator)** — Secure passwords
103
+ - **[Text Counter](https://devkits-tools.surge.sh/tools/text-counter)** — Word/char counter
104
+
105
+ ---
106
+
107
+ ### More from DevKits
108
+
109
+ - **[Invoicely](https://invoicely-app.surge.sh)** — Free invoice generator for freelancers
110
+ - **[SnapOG](https://snapog.surge.sh)** — Free OG image generator with 20+ templates
111
+ - **[API Monitor](https://api-monitor-saas.surge.sh)** — Real-time API monitoring
112
+
113
+ ---
114
+
115
+ 👉 **Explore all 80+ developer tools at [DevKits Tools](https://devkits-tools.surge.sh)**
116
+
117
+ ## License
118
+
119
+ MIT © [DevKits Team](https://devkits-tools.surge.sh)
120
+
121
+ ---
122
+
123
+ ## 🚀 API Monitoring for Developers
124
+
125
+ Build better APIs with **API Monitor SaaS** — real-time monitoring, alerting, and analytics.
126
+
127
+ 👉 **Early Access: $1 pre-order (50% off for life)** → https://api-monitor-saas.surge.sh?utm_source=npm&utm_medium=readme&utm_campaign=phase0
package/index.js ADDED
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @devkits/timestamp - Convert Unix timestamps to human-readable dates
5
+ *
6
+ * Usage:
7
+ * dk-timestamp # Current timestamp
8
+ * dk-timestamp 1704067200 # Convert to date
9
+ * dk-timestamp -d "2024-01-01" # Date to timestamp
10
+ *
11
+ * Web version: https://devkits-tools.surge.sh/tools/timestamp
12
+ * Pro features: https://devkits-tools.surge.sh/pro
13
+ */
14
+
15
+ function formatTimestamp(ts) {
16
+ const date = new Date(ts * 1000);
17
+ return {
18
+ timestamp: ts,
19
+ iso: date.toISOString(),
20
+ utc: date.toUTCString(),
21
+ local: date.toString(),
22
+ date: date.toLocaleDateString(),
23
+ time: date.toLocaleTimeString(),
24
+ };
25
+ }
26
+
27
+ function parseDate(dateStr) {
28
+ const date = new Date(dateStr);
29
+ if (isNaN(date.getTime())) {
30
+ throw new Error(`Invalid date: ${dateStr}`);
31
+ }
32
+ return Math.floor(date.getTime() / 1000);
33
+ }
34
+
35
+ function showHelp() {
36
+ console.log(`
37
+ @devkits/timestamp - Unix timestamp converter
38
+
39
+ Usage:
40
+ dk-timestamp # Current timestamp
41
+ dk-timestamp 1704067200 # Timestamp to date
42
+ dk-timestamp -d "2024-01-01" # Date to timestamp
43
+ dk-timestamp -d "Jan 1, 2024" # Flexible date parsing
44
+
45
+ Options:
46
+ -d, --date <date> Convert date string to timestamp
47
+ -f, --format <fmt> Output format: iso, utc, local, date, time
48
+ -h, --help Show this help message
49
+
50
+ Examples:
51
+ dk-timestamp # Current: 1704067200
52
+ dk-timestamp 1704067200 # 2024-01-01 00:00:00 UTC
53
+ dk-timestamp -d "2024-01-01" # 1704067200
54
+ dk-timestamp -d "2024-01-01" -f iso # 2024-01-01T00:00:00.000Z
55
+
56
+ Web version: https://devkits-tools.surge.sh/tools/timestamp
57
+ Pro features: https://devkits-tools.surge.sh/pro
58
+ `);
59
+ }
60
+
61
+ // Main entry point
62
+ const args = process.argv.slice(2);
63
+
64
+ if (!args.length || args.includes('-h') || args.includes('--help')) {
65
+ showHelp();
66
+ process.exit(0);
67
+ }
68
+
69
+ // Parse options
70
+ let dateStr = null;
71
+ let format = null;
72
+ let timestamp = null;
73
+
74
+ for (let i = 0; i < args.length; i++) {
75
+ if (args[i] === '-d' || args[i] === '--date') {
76
+ dateStr = args[++i];
77
+ } else if (args[i] === '-f' || args[i] === '--format') {
78
+ format = args[++i];
79
+ } else {
80
+ timestamp = parseInt(args[i], 10);
81
+ }
82
+ }
83
+
84
+ try {
85
+ if (dateStr) {
86
+ // Date to timestamp
87
+ const ts = parseDate(dateStr);
88
+ if (format) {
89
+ const date = new Date(ts * 1000);
90
+ switch (format) {
91
+ case 'iso':
92
+ console.log(date.toISOString());
93
+ break;
94
+ case 'utc':
95
+ console.log(date.toUTCString());
96
+ break;
97
+ case 'local':
98
+ console.log(date.toString());
99
+ break;
100
+ case 'date':
101
+ console.log(date.toLocaleDateString());
102
+ break;
103
+ case 'time':
104
+ console.log(date.toLocaleTimeString());
105
+ break;
106
+ default:
107
+ console.log(ts);
108
+ }
109
+ } else {
110
+ console.log(ts);
111
+ }
112
+ } else if (timestamp) {
113
+ // Timestamp to date
114
+ const result = formatTimestamp(timestamp);
115
+ if (format && result[format]) {
116
+ console.log(result[format]);
117
+ } else {
118
+ console.log(JSON.stringify(result, null, 2));
119
+ }
120
+ } else {
121
+ // Current timestamp
122
+ const now = Math.floor(Date.now() / 1000);
123
+ console.log(now);
124
+ }
125
+ } catch (err) {
126
+ console.error(`Error: ${err.message}`);
127
+ process.exit(1);
128
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "devkits-timestamp",
3
+ "version": "1.0.0",
4
+ "description": "Convert Unix timestamps to human-readable dates and vice versa",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "dk-timestamp": "./index.js",
8
+ "timestamp-cli": "./index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node test.js"
12
+ },
13
+ "keywords": [
14
+ "timestamp",
15
+ "unix",
16
+ "epoch",
17
+ "date",
18
+ "convert",
19
+ "devkits",
20
+ "developer-tools",
21
+ "cli",
22
+ "command-line",
23
+ "nodejs",
24
+ "utility",
25
+ "productivity",
26
+ "dev-tools",
27
+ "free-tools"
28
+ ],
29
+ "author": "DevKits Team <devkits-auto@protonmail.com>",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/devkits/tools"
34
+ },
35
+ "homepage": "https://devkits-tools.surge.sh/tools/timestamp",
36
+ "bugs": {
37
+ "url": "https://github.com/devkits/tools/issues"
38
+ },
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ },
42
+ "files": [
43
+ "index.js",
44
+ "README.md",
45
+ "test.js"
46
+ ],
47
+ "dependencies": {}
48
+ }
package/test.js ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Tests for @devkits/timestamp
5
+ */
6
+
7
+ const { execSync } = require('child_process');
8
+
9
+ const tests = [
10
+ {
11
+ name: 'Current timestamp is a number',
12
+ cmd: 'node index.js',
13
+ check: (result) => /^\d{10}$/.test(result.trim())
14
+ },
15
+ {
16
+ name: 'Timestamp to date (JSON output)',
17
+ cmd: 'node index.js 1704067200',
18
+ check: (result) => result.includes('2024-01-01') && result.includes('1704067200')
19
+ },
20
+ {
21
+ name: 'Timestamp to ISO format',
22
+ cmd: 'node index.js 1704067200 -f iso',
23
+ check: (result) => result.includes('2024-01-01')
24
+ },
25
+ {
26
+ name: 'Date to timestamp',
27
+ cmd: 'node index.js -d "2024-01-01"',
28
+ check: (result) => parseInt(result.trim()) === 1704067200
29
+ },
30
+ {
31
+ name: 'Date with time to timestamp',
32
+ cmd: 'node index.js -d "2024-01-01 12:00:00"',
33
+ check: (result) => parseInt(result.trim()) === 1704110400
34
+ },
35
+ ];
36
+
37
+ let passed = 0;
38
+ let failed = 0;
39
+
40
+ console.log('Running @devkits/timestamp tests...\n');
41
+
42
+ for (const test of tests) {
43
+ try {
44
+ const result = execSync(test.cmd, { encoding: 'utf8' }).trim();
45
+ if (test.check(result)) {
46
+ console.log(`✅ ${test.name}`);
47
+ passed++;
48
+ } else {
49
+ console.log(`❌ ${test.name}`);
50
+ console.log(` Got: ${result}`);
51
+ failed++;
52
+ }
53
+ } catch (err) {
54
+ console.log(`❌ ${test.name} - Error: ${err.message}`);
55
+ failed++;
56
+ }
57
+ }
58
+
59
+ console.log(`\n${passed}/${tests.length} tests passed`);
60
+ process.exit(failed > 0 ? 1 : 0);